Skip to content

Commit dd5371d

Browse files
committed
Support logging to log file
1 parent c99d897 commit dd5371d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Sources/Core/Helpers/Loger.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ public struct Logger {
4949
) {
5050
guard let desktopDir = NSSearchPathForDirectoriesInDomains(.desktopDirectory, .userDomainMask, true).last else { return }
5151
let string = event.icon + " \(Date()): " + messages.map { "\($0) " }.joined()
52-
try? string.write(toFile: desktopDir + "//log.txt", atomically: true, encoding: .utf8)
53-
}
54-
55-
public func log(_ str: String) {
52+
guard let desktopUrl = URL(string: desktopDir) else { return }
53+
let fileContent = (try? String(contentsOf: desktopUrl.appendingPathComponent("log.txt"))) ?? ""
54+
let finalLog = fileContent.appending("\n " + string)
5655

56+
try? finalLog.write(toFile: desktopDir + "//log.txt", atomically: true, encoding: .utf8)
5757
}
58+
5859

5960
}
6061

Sources/Core/Highligher/Highlighter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public struct Highlighter {
1717
.map { $0.kind.rawValue + " \($0.range.lowerBound) \($0.range.upperBound)" }
1818
.joined(separator: " ")
1919
Logger.log(event: .debug, destination: .disk, messages: log)
20-
tokens.forEach({ token in
20+
tokens.forEach { token in
2121
let color = self.color(for: token.kind)
2222
code.highlight(token.text, with: color, at: token.range)
23-
})
23+
}
2424

2525
Logger.log(event: .debug, destination: .disk, messages: code)
2626
return code
2727
}
2828
}
2929

3030
private extension Highlighter {
31-
func color(for key: TokenType) -> Color {
32-
config.theme.highlights[key] ?? Color(r: 250, g: 141, b: 87)
31+
func color(for token: TokenType) -> Color {
32+
config.theme.highlights[token] ?? Color(r: 250, g: 141, b: 87)
3333
}
3434
}
3535

0 commit comments

Comments
 (0)