Skip to content

Commit

Permalink
Support logging to log file
Browse files Browse the repository at this point in the history
  • Loading branch information
engali94 committed Dec 12, 2021
1 parent c99d897 commit dd5371d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Sources/Core/Helpers/Loger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public struct Logger {
) {
guard let desktopDir = NSSearchPathForDirectoriesInDomains(.desktopDirectory, .userDomainMask, true).last else { return }
let string = event.icon + " \(Date()): " + messages.map { "\($0) " }.joined()
try? string.write(toFile: desktopDir + "//log.txt", atomically: true, encoding: .utf8)
}

public func log(_ str: String) {
guard let desktopUrl = URL(string: desktopDir) else { return }
let fileContent = (try? String(contentsOf: desktopUrl.appendingPathComponent("log.txt"))) ?? ""
let finalLog = fileContent.appending("\n " + string)

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


}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Core/Highligher/Highlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public struct Highlighter {
.map { $0.kind.rawValue + " \($0.range.lowerBound) \($0.range.upperBound)" }
.joined(separator: " ")
Logger.log(event: .debug, destination: .disk, messages: log)
tokens.forEach({ token in
tokens.forEach { token in
let color = self.color(for: token.kind)
code.highlight(token.text, with: color, at: token.range)
})
}

Logger.log(event: .debug, destination: .disk, messages: code)
return code
}
}

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

Expand Down

0 comments on commit dd5371d

Please sign in to comment.