@@ -11,8 +11,14 @@ public class PrintLogWriter: LogWriterProtocol {
1111 /// - severity: The severity level of the message.
1212 /// - message: The content of the log message.
1313 /// - tag: An optional tag used to categorize the message. If empty, no brackets are shown.
14- public func log( severity: LogSeverity , message: String , tag: String ) {
15- let tagPrefix = tag. isEmpty ? " " : " [ \( tag) ] "
14+ public func log( severity: LogSeverity , message: String , tag: String ? ) {
15+ let tagPrefix : String
16+ if let tag, !tag. isEmpty {
17+ tagPrefix = " [ \( tag) ] "
18+ } else {
19+ tagPrefix = " "
20+ }
21+
1622 let message = " \( tagPrefix) \( message) "
1723 if #available( iOS 14 . 0 , * ) {
1824 let l = Logger ( )
@@ -30,21 +36,21 @@ public class PrintLogWriter: LogWriterProtocol {
3036 l. fault ( " \( message) " )
3137 }
3238 } else {
33- print ( " \( severity. rawValue ) : \( message) " )
39+ print ( " \( severity. stringValue ) : \( message) " )
3440 }
3541 }
3642}
3743
38- /// A default logger configuration that uses `SwiftLogWritter` and filters messages by minimum severity.
39- ///
40- /// This logger integrates with your custom logging system and uses `os.Logger` under the hood.
44+ /// A default logger configuration that uses `PrintLogWritter` and filters messages by minimum severity.
4145public class DefaultLogger : LoggerProtocol {
4246 public var minSeverirty : LogSeverity
4347 public var writers : [ any LogWriterProtocol ]
4448
4549 /// Initializes the default logger with an optional minimum severity level.
4650 ///
47- /// - Parameter minSeverity: The minimum severity level to log. Defaults to `.debug`.
51+ /// - Parameters
52+ /// - minSeverity: The minimum severity level to log. Defaults to `.debug`.
53+ /// - writers: Optional writers which logs should be written to. Defaults to a `PrintLogWriter`.
4854 public init ( minSeverity: LogSeverity = . debug, writers: [ any LogWriterProtocol ] ? = nil ) {
4955 self . writers = writers ?? [ PrintLogWriter ( ) ]
5056 self . minSeverirty = minSeverity
@@ -59,27 +65,27 @@ public class DefaultLogger: LoggerProtocol {
5965 }
6066
6167
62- public func debug( _ message: String , tag: String ) {
63- self . writeLog ( message, tag : tag , severity: LogSeverity . debug)
68+ public func debug( _ message: String , tag: String ? = nil ) {
69+ self . writeLog ( message, severity: LogSeverity . debug, tag : tag )
6470 }
6571
66- public func error( _ message: String , tag: String ) {
67- self . writeLog ( message, tag : tag , severity: LogSeverity . error)
72+ public func error( _ message: String , tag: String ? = nil ) {
73+ self . writeLog ( message, severity: LogSeverity . error, tag : tag )
6874 }
6975
70- public func info( _ message: String , tag: String ) {
71- self . writeLog ( message, tag : tag , severity: LogSeverity . info)
76+ public func info( _ message: String , tag: String ? = nil ) {
77+ self . writeLog ( message, severity: LogSeverity . info, tag : tag )
7278 }
7379
74- public func warning( _ message: String , tag: String ) {
75- self . writeLog ( message, tag : tag , severity: LogSeverity . warning)
80+ public func warning( _ message: String , tag: String ? = nil ) {
81+ self . writeLog ( message, severity: LogSeverity . warning, tag : tag )
7682 }
7783
78- public func fault( _ message: String , tag: String ) {
79- self . writeLog ( message, tag : tag , severity: LogSeverity . fault)
84+ public func fault( _ message: String , tag: String ? = nil ) {
85+ self . writeLog ( message, severity: LogSeverity . fault, tag : tag )
8086 }
8187
82- private func writeLog( _ message: String , tag : String , severity : LogSeverity ) {
88+ private func writeLog( _ message: String , severity : LogSeverity , tag : String ? ) {
8389 if ( severity. rawValue < self . minSeverirty. rawValue) {
8490 return
8591 }
0 commit comments