@@ -34,15 +34,17 @@ import (
3434 "aahframework.org/config.v0"
3535)
3636
37- // Level type definition
38- type Level uint8
37+ type (
38+ // FmtFlag type definition
39+ fmtFlag uint8
3940
40- // FmtFlag type definition
41- type FmtFlag uint8
41+ // Level type definition
42+ level uint8
43+ )
4244
4345// Log Level definition
4446const (
45- levelFatal Level = iota
47+ levelFatal level = iota
4648 levelPanic
4749 LevelError
4850 LevelWarn
@@ -54,7 +56,7 @@ const (
5456
5557// Format flags used to define log message format for each log entry
5658const (
57- FmtFlagLevel FmtFlag = iota
59+ FmtFlagLevel fmtFlag = iota
5860 FmtFlagTime
5961 FmtFlagUTCTime
6062 FmtFlagLongfile
@@ -67,7 +69,7 @@ const (
6769
6870var (
6971 // Version no. of aahframework.org/log library
70- Version = "0.4 "
72+ Version = "0.5 "
7173
7274 // FmtFlags is the list of log format flags supported by aah/log library
7375 // Usage of flag order is up to format composition.
7981 // line - outputs file line number: L23
8082 // message - outputs given message along supplied arguments if they present
8183 // custom - outputs string as-is into log entry
82- FmtFlags = map [string ]FmtFlag {
84+ FmtFlags = map [string ]fmtFlag {
8385 "level" : FmtFlagLevel ,
8486 "time" : FmtFlagTime ,
8587 "utctime" : FmtFlagUTCTime ,
@@ -106,6 +108,9 @@ var (
106108 flagValueSeparator = ":"
107109 defaultFormat = "%v"
108110 filePermission = os .FileMode (0755 )
111+
112+ // abstract it, can be unit tested
113+ exit = os .Exit
109114)
110115
111116type (
@@ -125,7 +130,7 @@ type (
125130 Logger struct {
126131 cfg * config.Config
127132 m * sync.Mutex
128- level Level
133+ level level
129134 receiver Receiver
130135 }
131136)
@@ -288,19 +293,19 @@ func (l *Logger) Println(format string, v ...interface{}) {
288293// Fatal logs message as `FATAL` and call to os.Exit(1).
289294func (l * Logger ) Fatal (v ... interface {}) {
290295 l .output (levelFatal , 3 , nil , v ... )
291- os . Exit (1 )
296+ exit (1 )
292297}
293298
294299// Fatalf logs message as `FATAL` and call to os.Exit(1).
295300func (l * Logger ) Fatalf (format string , v ... interface {}) {
296301 l .output (levelFatal , 3 , & format , v ... )
297- os . Exit (1 )
302+ exit (1 )
298303}
299304
300305// Fatalln logs message as `FATAL` and call to os.Exit(1).
301306func (l * Logger ) Fatalln (format string , v ... interface {}) {
302307 l .output (levelFatal , 3 , & format , v ... )
303- os . Exit (1 )
308+ exit (1 )
304309}
305310
306311// Panic logs message as `PANIC` and call to panic().
@@ -321,13 +326,42 @@ func (l *Logger) Panicln(format string, v ...interface{}) {
321326 panic (fmt .Sprintf (format , v ... ))
322327}
323328
329+ //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
330+ // Logger level methods
331+ //___________________________________
332+
333+ // IsLevelInfo method returns true if log level is INFO otherwise false.
334+ func (l * Logger ) IsLevelInfo () bool {
335+ return l .level == LevelInfo
336+ }
337+
338+ // IsLevelError method returns true if log level is ERROR otherwise false.
339+ func (l * Logger ) IsLevelError () bool {
340+ return l .level == LevelError
341+ }
342+
343+ // IsLevelWarn method returns true if log level is WARN otherwise false.
344+ func (l * Logger ) IsLevelWarn () bool {
345+ return l .level == LevelWarn
346+ }
347+
348+ // IsLevelDebug method returns true if log level is DEBUG otherwise false.
349+ func (l * Logger ) IsLevelDebug () bool {
350+ return l .level == LevelDebug
351+ }
352+
353+ // IsLevelTrace method returns true if log level is TRACE otherwise false.
354+ func (l * Logger ) IsLevelTrace () bool {
355+ return l .level == LevelTrace
356+ }
357+
324358//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
325359// Unexported methods
326360//___________________________________
327361
328362// output method checks the level, formats the arguments and call to configured
329363// Log receivers.
330- func (l * Logger ) output (level Level , calldepth int , format * string , v ... interface {}) {
364+ func (l * Logger ) output (level level , calldepth int , format * string , v ... interface {}) {
331365 if level > l .level {
332366 return
333367 }
0 commit comments