-
Notifications
You must be signed in to change notification settings - Fork 7
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
36 changed files
with
673 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Foundation | ||
|
||
#if canImport(OSLog) | ||
import OSLog | ||
#endif | ||
|
||
/// The OSLoggerAppender class can output your Console.app with os_log function. | ||
/// - seealso: https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code | ||
@available(iOS 14.0, *) | ||
@available(macOS 11.0, *) | ||
@available(tvOS 14.0, *) | ||
@available(watchOS 7.0, *) | ||
public class OSLoggerAppender: LogboardAppender { | ||
private let logger: Logger | ||
|
||
/// Creates a logger using the specified subsystem and category. | ||
public init(sybsystem: String, category: String) { | ||
logger = Logger(subsystem: sybsystem, category: category) | ||
} | ||
|
||
public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) { | ||
let message = | ||
"[\(filename(file.description)):\(line)]" + | ||
function.description + | ||
">" + | ||
message.map({ String(describing: $0) }).joined(separator: "") | ||
switch level { | ||
case .trace: | ||
logger.trace("\(message)") | ||
case .debug: | ||
logger.debug("\(message)") | ||
case .info: | ||
logger.info("\(message)") | ||
case .warn: | ||
logger.warning("\(message)") | ||
case .error: | ||
logger.error("\(message)") | ||
} | ||
} | ||
|
||
public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) { | ||
let message = | ||
"[\(filename(file.description)):\(line)]" + | ||
function.description + | ||
">" + | ||
String(format: format, arguments) | ||
switch level { | ||
case .trace: | ||
logger.trace("\(message)") | ||
case .debug: | ||
logger.debug("\(message)") | ||
case .info: | ||
logger.info("\(message)") | ||
case .warn: | ||
logger.warning("\(message)") | ||
case .error: | ||
logger.error("\(message)") | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.