| 1 | package logrscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/ |
| 2 | |
| 3 | import ( |
| 4 | "ioscip-go gomod github.com/golang/go/src go1.23.3 io/" |
| 5 | "logscip-go gomod github.com/golang/go/src go1.23.3 log/" |
| 6 | "osscip-go gomod github.com/golang/go/src go1.23.3 os/" |
| 7 | ) |
| 8 | |
| 9 | var defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger. = Newscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/New().(LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo., false, osscip-go gomod github.com/golang/go/src go1.23.3 os/.Stdoutscip-go gomod github.com/golang/go/src go1.23.3 os/Stdout.) |
| 10 | |
| 11 | type Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger# struct { |
| 12 | // threshold is the minimum level output by this logger. |
| 13 | // |
| 14 | // For example, if the threshold is set to LevelWarn, then only logs of LevelWarn and LevelError will be output |
| 15 | // while logs of LevelDebug and LevelInfo will be ignored. |
| 16 | // |
| 17 | // Defaults to LevelInfo. |
| 18 | thresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#threshold. Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# |
| 19 | |
| 20 | // shouldPrefixMessageWithLevel is whether to include the log level prefix in each log. |
| 21 | // |
| 22 | // For example, if this is set to true, then a debug log would output "<date> DEBUG <message>" |
| 23 | // |
| 24 | // Defaults to false. |
| 25 | shouldPrefixMessageWithLevelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#shouldPrefixMessageWithLevel. bool |
| 26 | |
| 27 | stdLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#stdLogger. *logscip-go gomod github.com/golang/go/src go1.23.3 log/.Loggerscip-go gomod github.com/golang/go/src go1.23.3 log/Logger# |
| 28 | } |
| 29 | |
| 30 | // New creates a new logger with the given threshold and output. |
| 31 | func Newscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/New().(threshold Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#, shouldPrefixMessageWithLevel bool, output ioscip-go gomod github.com/golang/go/src go1.23.3 io/.Writerscip-go gomod github.com/golang/go/src go1.23.3 io/Writer#) *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger# { |
| 32 | if !threshold.IsValidscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#IsValid().() { |
| 33 | threshold = LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo. // Default to LevelInfo if the threshold is invalid |
| 34 | } |
| 35 | return &Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#{ |
| 36 | thresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#threshold.: threshold, |
| 37 | shouldPrefixMessageWithLevelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#shouldPrefixMessageWithLevel.: shouldPrefixMessageWithLevel, |
| 38 | stdLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#stdLogger.: logscip-go gomod github.com/golang/go/src go1.23.3 log/.Newscip-go gomod github.com/golang/go/src go1.23.3 log/New().(output, "", logscip-go gomod github.com/golang/go/src go1.23.3 log/.LstdFlagsscip-go gomod github.com/golang/go/src go1.23.3 log/LstdFlags.), |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) SetOutputscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#SetOutput().(output ioscip-go gomod github.com/golang/go/src go1.23.3 io/.Writerscip-go gomod github.com/golang/go/src go1.23.3 io/Writer#) { |
| 43 | // Because we're using the standard log package under the hood, we can just directly pass this |
| 44 | // to the logger and call it a day. It already takes care of locking and discarding the previous writer. |
| 45 | logger.stdLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#stdLogger..SetOutputscip-go gomod github.com/golang/go/src go1.23.3 log/Logger#SetOutput().(output) |
| 46 | } |
| 47 | |
| 48 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) SetThresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#SetThreshold().(threshold Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#) { |
| 49 | if !threshold.IsValidscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#IsValid().() { |
| 50 | threshold = LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo. // Default to LevelInfo if the threshold is invalid |
| 51 | } else { |
| 52 | logger.thresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#threshold. = threshold |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) GetThresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#GetThreshold().() Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# { |
| 57 | return logger.thresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#threshold. |
| 58 | } |
| 59 | |
| 60 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(level Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#, message string) { |
| 61 | logger.Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(level, message) |
| 62 | } |
| 63 | |
| 64 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(level Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#, format string, args ...any) { |
| 65 | if level.Valuescip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#Value().() < logger.thresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#threshold..Valuescip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#Value().() { |
| 66 | // The log level is below the threshold, so ignore the log |
| 67 | return |
| 68 | } |
| 69 | if logger.shouldPrefixMessageWithLevelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#shouldPrefixMessageWithLevel. { |
| 70 | format = "- " + string(level) + " - " + format |
| 71 | } |
| 72 | logger.stdLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#stdLogger..Printfscip-go gomod github.com/golang/go/src go1.23.3 log/Logger#Printf().(format, args...) |
| 73 | if level == LevelFatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFatal. { |
| 74 | osscip-go gomod github.com/golang/go/src go1.23.3 os/.Exitscip-go gomod github.com/golang/go/src go1.23.3 os/Exit().(1) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Debugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Debug().(message string) { |
| 79 | logger.Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(LevelDebugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelDebug., message) |
| 80 | } |
| 81 | |
| 82 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Debugfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Debugf().(format string, args ...any) { |
| 83 | logger.Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(LevelDebugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelDebug., format, args...) |
| 84 | } |
| 85 | |
| 86 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Infoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Info().(message string) { |
| 87 | logger.Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo., message) |
| 88 | } |
| 89 | |
| 90 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Infofscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Infof().(format string, args ...any) { |
| 91 | logger.Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(LevelInfoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelInfo., format, args...) |
| 92 | } |
| 93 | |
| 94 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Warnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Warn().(message string) { |
| 95 | logger.Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(LevelWarnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelWarn., message) |
| 96 | } |
| 97 | |
| 98 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Warnfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Warnf().(format string, args ...any) { |
| 99 | logger.Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(LevelWarnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelWarn., format, args...) |
| 100 | } |
| 101 | |
| 102 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Errorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Error().(message string) { |
| 103 | logger.Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(LevelErrorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelError., message) |
| 104 | } |
| 105 | |
| 106 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Errorfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Errorf().(format string, args ...any) { |
| 107 | logger.Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(LevelErrorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelError., format, args...) |
| 108 | } |
| 109 | |
| 110 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Fatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Fatal().(message string) { |
| 111 | logger.Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(LevelFatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFatal., message) |
| 112 | } |
| 113 | |
| 114 | func (logger *Loggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#) Fatalfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Fatalf().(format string, args ...any) { |
| 115 | logger.Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(LevelFatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/LevelFatal., format, args...) |
| 116 | } |
| 117 | |
| 118 | // SetOutput sets the output of the default logger |
| 119 | func SetOutputscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/SetOutput().(output ioscip-go gomod github.com/golang/go/src go1.23.3 io/.Writerscip-go gomod github.com/golang/go/src go1.23.3 io/Writer#) { |
| 120 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..SetOutputscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#SetOutput().(output) |
| 121 | } |
| 122 | |
| 123 | // SetThreshold sets the minimum level output by the default logger |
| 124 | func SetThresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/SetThreshold().(threshold Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#) { |
| 125 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..SetThresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#SetThreshold().(threshold) |
| 126 | } |
| 127 | |
| 128 | func GetThresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/GetThreshold().() Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level# { |
| 129 | return defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..GetThresholdscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#GetThreshold().() |
| 130 | } |
| 131 | |
| 132 | func Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Log().(level Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#, message string) { |
| 133 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Logscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Log().(level, message) |
| 134 | } |
| 135 | |
| 136 | func Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logf().(level Levelscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Level#, message string, args ...any) { |
| 137 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Logfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Logf().(level, message, args) |
| 138 | } |
| 139 | |
| 140 | func Debugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Debug().(message string) { |
| 141 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Debugscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Debug().(message) |
| 142 | } |
| 143 | |
| 144 | func Debugfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Debugf().(format string, args ...any) { |
| 145 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Debugfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Debugf().(format, args...) |
| 146 | } |
| 147 | |
| 148 | func Infoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Info().(message string) { |
| 149 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Infoscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Info().(message) |
| 150 | } |
| 151 | |
| 152 | func Infofscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Infof().(format string, args ...any) { |
| 153 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Infofscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Infof().(format, args...) |
| 154 | } |
| 155 | |
| 156 | func Warnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Warn().(message string) { |
| 157 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Warnscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Warn().(message) |
| 158 | } |
| 159 | |
| 160 | func Warnfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Warnf().(format string, args ...any) { |
| 161 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Warnfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Warnf().(format, args...) |
| 162 | } |
| 163 | |
| 164 | func Errorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Error().(message string) { |
| 165 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Errorscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Error().(message) |
| 166 | } |
| 167 | |
| 168 | func Errorfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Errorf().(format string, args ...any) { |
| 169 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Errorfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Errorf().(format, args...) |
| 170 | } |
| 171 | |
| 172 | func Fatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Fatal().(message string) { |
| 173 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Fatalscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Fatal().(message) |
| 174 | } |
| 175 | |
| 176 | func Fatalfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Fatalf().(format string, args ...any) { |
| 177 | defaultLoggerscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/defaultLogger..Fatalfscip-go gomod github.com/TwiN/logr . `github.com/TwiN/logr`/Logger#Fatalf().(format, args...) |
| 178 | } |