@@ -7,106 +7,123 @@ package log
77import (
88 "fmt"
99 "os"
10- )
1110
12- var stdLogger Logger
11+ "aahframework.org/config.v0"
12+ )
1313
14- // Fatal logs message as `FATAL` and calls os.Exit(1)
15- func Fatal (v ... interface {}) {
16- _ = stdLogger .Output (levelFatal , 2 , nil , v ... )
17- os .Exit (1 )
18- }
14+ var std * Logger
1915
20- // Fatalf logs message as `FATAL` and calls os.Exit(1)
21- func Fatalf (format string , v ... interface {}) {
22- _ = stdLogger .Output (levelFatal , 2 , & format , v ... )
23- os .Exit (1 )
24- }
16+ //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
17+ // Logger methods
18+ //_______________________________________
2519
26- // Panic logs message as `PANIC` and calls panic()
27- func Panic (v ... interface {}) {
28- _ = stdLogger .Output (levelPanic , 2 , nil , v ... )
29- panic ("" )
30- }
31-
32- // Panicf logs message as `PANIC` and calls panic()
33- func Panicf (format string , v ... interface {}) {
34- _ = stdLogger .Output (levelPanic , 2 , & format , v ... )
35- panic (fmt .Sprintf (format , v ... ))
36- }
37-
38- // Error logs message as `LevelError`
20+ // Error logs message as `ERROR`. Arguments handled in the mananer of `fmt.Print`.
3921func Error (v ... interface {}) {
40- _ = stdLogger . Output (LevelError , 2 , nil , v ... )
22+ std . output (LevelError , 3 , nil , v ... )
4123}
4224
43- // Errorf logs message as `LevelError`
25+ // Errorf logs message as `ERROR`. Arguments handled in the mananer of `fmt.Printf`.
4426func Errorf (format string , v ... interface {}) {
45- _ = stdLogger . Output (LevelError , 2 , & format , v ... )
27+ std . output (LevelError , 3 , & format , v ... )
4628}
4729
48- // Warn logs message as `LevelWarn`
30+ // Warn logs message as `WARN`. Arguments handled in the mananer of `fmt.Print`.
4931func Warn (v ... interface {}) {
50- _ = stdLogger . Output (LevelWarn , 2 , nil , v ... )
32+ std . output (LevelWarn , 3 , nil , v ... )
5133}
5234
53- // Warnf logs message as `LevelWarn`
35+ // Warnf logs message as `WARN`. Arguments handled in the mananer of `fmt.Printf`.
5436func Warnf (format string , v ... interface {}) {
55- _ = stdLogger . Output (LevelWarn , 2 , & format , v ... )
37+ std . output (LevelWarn , 3 , & format , v ... )
5638}
5739
58- // Info logs message as `LevelInfo`
40+ // Info logs message as `INFO`. Arguments handled in the mananer of `fmt.Print`.
5941func Info (v ... interface {}) {
60- _ = stdLogger . Output (LevelInfo , 2 , nil , v ... )
42+ std . output (LevelInfo , 3 , nil , v ... )
6143}
6244
63- // Infof logs message as `LevelInfo`
45+ // Infof logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
6446func Infof (format string , v ... interface {}) {
65- _ = stdLogger . Output (LevelInfo , 2 , & format , v ... )
47+ std . output (LevelInfo , 3 , & format , v ... )
6648}
6749
68- // Debug logs message as `LevelDebug`
50+ // Debug logs message as `DEBUG`. Arguments handled in the mananer of `fmt.Print`.
6951func Debug (v ... interface {}) {
70- _ = stdLogger . Output (LevelDebug , 2 , nil , v ... )
52+ std . output (LevelDebug , 3 , nil , v ... )
7153}
7254
73- // Debugf logs message as `LevelDebug`
55+ // Debugf logs message as `DEBUG`. Arguments handled in the mananer of `fmt.Printf`.
7456func Debugf (format string , v ... interface {}) {
75- _ = stdLogger . Output (LevelDebug , 2 , & format , v ... )
57+ std . output (LevelDebug , 3 , & format , v ... )
7658}
7759
78- // Trace logs message as `LevelTrace`
60+ // Trace logs message as `TRACE`. Arguments handled in the mananer of `fmt.Print`.
7961func Trace (v ... interface {}) {
80- _ = stdLogger . Output (LevelTrace , 2 , nil , v ... )
62+ std . output (LevelTrace , 3 , nil , v ... )
8163}
8264
83- // Tracef logs message as `LevelTrace`
65+ // Tracef logs message as `TRACE`. Arguments handled in the mananer of `fmt.Printf`.
8466func Tracef (format string , v ... interface {}) {
85- _ = stdLogger . Output (LevelTrace , 2 , & format , v ... )
67+ std . output (LevelTrace , 3 , & format , v ... )
8668}
8769
88- // Stats returns current logger statistics like number of lines written,
89- // number of bytes written, etc.
90- func Stats () * ReceiverStats {
91- return stdLogger .Stats ()
70+ //‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
71+ // Logger methods - Drop-in replacement
72+ // for Go standard logger
73+ //_______________________________________
74+
75+ // Print logs message as `INFO`. Arguments handled in the mananer of `fmt.Print`.
76+ func Print (v ... interface {}) {
77+ std .output (LevelInfo , 3 , nil , v ... )
9278}
9379
94- // SetPattern sets the log entry format
95- func SetPattern ( pattern string ) error {
96- return stdLogger . SetPattern ( pattern )
80+ // Printf logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
81+ func Printf ( format string , v ... interface {}) {
82+ std . output ( LevelInfo , 3 , & format , v ... )
9783}
9884
99- // SetLevel allows to set log level dynamically
100- func SetLevel ( level Level ) {
101- stdLogger . SetLevel ( level )
85+ // Println logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
86+ func Println ( format string , v ... interface {} ) {
87+ std . output ( LevelInfo , 3 , & format , v ... )
10288}
10389
104- // SetOutput allows to set standard logger implementation
105- // which statisfies `Logger` interface
106- func SetOutput (logger Logger ) {
107- stdLogger = logger
90+ // Fatal logs message as `FATAL` and call to os.Exit(1).
91+ func Fatal (v ... interface {}) {
92+ std .output (levelFatal , 3 , nil , v ... )
93+ os .Exit (1 )
94+ }
95+
96+ // Fatalf logs message as `FATAL` and call to os.Exit(1).
97+ func Fatalf (format string , v ... interface {}) {
98+ std .output (levelFatal , 3 , & format , v ... )
99+ os .Exit (1 )
100+ }
101+
102+ // Fatalln logs message as `FATAL` and call to os.Exit(1).
103+ func Fatalln (format string , v ... interface {}) {
104+ std .output (levelFatal , 3 , & format , v ... )
105+ os .Exit (1 )
106+ }
107+
108+ // Panic logs message as `PANIC` and call to panic().
109+ func Panic (v ... interface {}) {
110+ std .output (levelPanic , 3 , nil , v ... )
111+ panic ("" )
112+ }
113+
114+ // Panicf logs message as `PANIC` and call to panic().
115+ func Panicf (format string , v ... interface {}) {
116+ std .output (levelPanic , 3 , & format , v ... )
117+ panic (fmt .Sprintf (format , v ... ))
118+ }
119+
120+ // Panicln logs message as `PANIC` and call to panic().
121+ func Panicln (format string , v ... interface {}) {
122+ std .output (levelPanic , 3 , & format , v ... )
123+ panic (fmt .Sprintf (format , v ... ))
108124}
109125
110126func init () {
111- stdLogger , _ = New (`receiver = "CONSOLE"; level = "DEBUG";` )
127+ cfg , _ := config .ParseString ("log { }" )
128+ std , _ = New (cfg )
112129}
0 commit comments