@@ -66,6 +66,45 @@ public struct DisabledLogger: Logger {
6666 ) { }
6767}
6868
69+ /// A simple `print` logger suitable for debugging in terminal environments outside Xcode
70+ public struct PrintLogger : Logger {
71+ private let minLevel : LogLevel
72+ private let colors : Bool
73+
74+ public init ( minLevel: LogLevel = . info, colors: Bool = true ) {
75+ self . minLevel = minLevel
76+ self . colors = colors
77+ }
78+
79+ public func log(
80+ _ message: @autoclosure ( ) -> CustomStringConvertible ,
81+ _ level: LogLevel ,
82+ source _: @autoclosure ( ) -> String ? ,
83+ file _: StaticString ,
84+ type: Any . Type ,
85+ function: StaticString ,
86+ line _: UInt ,
87+ metaData _: ScopedMetadataContainer
88+ ) {
89+ guard level >= minLevel else { return }
90+ print ( " [ \( colorCode ( level) ) \( level) \( resetCode) ] \( type) . \( function) \( message ( ) ) " )
91+ }
92+
93+ private func colorCode( _ level: LogLevel ) -> String {
94+ guard colors else { return " " }
95+ switch level {
96+ case . debug: return " \u{001B} [36m "
97+ case . info: return " \u{001B} [94m "
98+ case . warning: return " \u{001B} [33m "
99+ case . error: return " \u{001B} [31m "
100+ }
101+ }
102+
103+ private var resetCode : String {
104+ colors ? " \u{001B} [0m " : " "
105+ }
106+ }
107+
69108/// A logger that logs to OSLog
70109/// - Parameter minLevel: The minimum level to log
71110/// - Parameter rtc: Whether to log WebRTC output
@@ -172,7 +211,7 @@ extension Loggable {
172211
173212@objc
174213@frozen
175- public enum LogLevel : Int , Sendable , Comparable {
214+ public enum LogLevel : Int , Sendable , Comparable , CustomStringConvertible {
176215 case debug
177216 case info
178217 case warning
@@ -201,6 +240,15 @@ public enum LogLevel: Int, Sendable, Comparable {
201240 public static func < ( lhs: LogLevel , rhs: LogLevel ) -> Bool {
202241 lhs. rawValue < rhs. rawValue
203242 }
243+
244+ public var description : String {
245+ switch self {
246+ case . debug: " Debug "
247+ case . info: " Info "
248+ case . warning: " Warning "
249+ case . error: " Error "
250+ }
251+ }
204252}
205253
206254extension LKRTCLoggingSeverity {
0 commit comments