-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
/* | ||
* Ax Editor | ||
* Copyright (c) Ali Hilal 2020 | ||
* MIT license - see LICENSE.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Ax Editor | ||
* Copyright (c) Ali Hilal 2021 | ||
* MIT license - see LICENSE.md | ||
*/ | ||
|
||
import Foundation | ||
import Logging | ||
|
||
public struct Logger { | ||
|
||
public typealias Level = Logging.Logger.Level | ||
|
||
private static let consoleLogger = Logging.Logger( | ||
label: "com.alihilal.ax-editor", | ||
factory: StreamLogHandler.standardError | ||
) | ||
|
||
public static func log( | ||
event: Level, | ||
destination: Destination = .console, | ||
messages: Any..., | ||
file: StaticString = #filePath, | ||
line: UInt = #line | ||
) { | ||
switch destination { | ||
case .console: | ||
logToConsole(event: event, messages: messages, file: file, line: line) | ||
case .disk: | ||
logToDisk(event: event, messages: messages, file: file, line: line) | ||
} | ||
} | ||
|
||
private static func logToConsole( | ||
event: Level, | ||
messages: Any..., | ||
file: StaticString = #filePath, | ||
line: UInt = #line | ||
) { | ||
let string = event.icon + " " + messages.map { "\($0) " }.joined() | ||
consoleLogger.log(level: event, .init(stringLiteral: string)) | ||
} | ||
|
||
private static func logToDisk( | ||
event: Level, | ||
messages: Any..., | ||
file: StaticString = #filePath, | ||
line: UInt = #line | ||
) { | ||
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) { | ||
|
||
} | ||
|
||
} | ||
|
||
public extension Logger { | ||
enum Destination { | ||
case console | ||
case disk | ||
} | ||
} | ||
|
||
extension Logger { | ||
enum Event { | ||
case debug | ||
case error | ||
case success | ||
} | ||
} | ||
|
||
|
||
extension Logger.Level { | ||
var icon: String { | ||
switch self { | ||
case .debug: | ||
return "⚙️" | ||
case .error: | ||
return "🚨" | ||
case .info: | ||
return "✅" | ||
case .trace: | ||
return "🔔" | ||
case .notice: | ||
return "ℹ️" | ||
case .warning: | ||
return "⚠️" | ||
case .critical: | ||
return "⛔️" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters