-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add structured logging as an alternative to stdout printing #150
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Foundation | ||
import OSLog | ||
|
||
public struct LogHandler { | ||
public enum LogLevel: Int, CustomStringConvertible { | ||
|
@@ -16,6 +17,17 @@ | |
return "ERROR" | ||
} | ||
} | ||
|
||
public var osLogLevel: OSLogType { | ||
switch self { | ||
case .debug: | ||
Check failure on line 23 in Sources/TelemetryClient/LogHandler.swift GitHub Actions / Lint Code
|
||
return OSLogType.debug | ||
case .info: | ||
return OSLogType.info | ||
case .error: | ||
return OSLogType.error | ||
} | ||
} | ||
} | ||
|
||
let logLevel: LogLevel | ||
|
@@ -32,6 +44,16 @@ | |
} | ||
} | ||
|
||
@available(iOS 14.0, macOS 11.0, watchOS 7.0, tvOS 14.0, *) | ||
public static var oslog = { logLevel in | ||
LogHandler(logLevel: logLevel) { level, message in | ||
Check failure on line 49 in Sources/TelemetryClient/LogHandler.swift GitHub Actions / Lint Code
|
||
Logger( | ||
subsystem: "TelemetryDeck", | ||
category: "LogHandler" | ||
).log(level: logLevel.osLogLevel, "\(message, privacy: .public)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the specifier |
||
} | ||
} | ||
|
||
public static var stdout = { logLevel in | ||
LogHandler(logLevel: logLevel) { level, message in | ||
print("[TelemetryDeck: \(level.description)] \(message)") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we really import
OSLog
just like that? I believe it's only available starting with iOS 15, so we need to at least check forcanImport
here, I think, since we're supporting iOS 12.