-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
144 lines (115 loc) · 4.15 KB
/
default.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (c) Jeevanandam M (https://github.com/jeevatkm)
// go-aah/log source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package log
import (
"fmt"
"os"
"aahframework.org/config.v0"
)
var std *Logger
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger methods
//_______________________________________
// Error logs message as `ERROR`. Arguments handled in the mananer of `fmt.Print`.
func Error(v ...interface{}) {
std.output(LevelError, 3, nil, v...)
}
// Errorf logs message as `ERROR`. Arguments handled in the mananer of `fmt.Printf`.
func Errorf(format string, v ...interface{}) {
std.output(LevelError, 3, &format, v...)
}
// Warn logs message as `WARN`. Arguments handled in the mananer of `fmt.Print`.
func Warn(v ...interface{}) {
std.output(LevelWarn, 3, nil, v...)
}
// Warnf logs message as `WARN`. Arguments handled in the mananer of `fmt.Printf`.
func Warnf(format string, v ...interface{}) {
std.output(LevelWarn, 3, &format, v...)
}
// Info logs message as `INFO`. Arguments handled in the mananer of `fmt.Print`.
func Info(v ...interface{}) {
std.output(LevelInfo, 3, nil, v...)
}
// Infof logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
func Infof(format string, v ...interface{}) {
std.output(LevelInfo, 3, &format, v...)
}
// Debug logs message as `DEBUG`. Arguments handled in the mananer of `fmt.Print`.
func Debug(v ...interface{}) {
std.output(LevelDebug, 3, nil, v...)
}
// Debugf logs message as `DEBUG`. Arguments handled in the mananer of `fmt.Printf`.
func Debugf(format string, v ...interface{}) {
std.output(LevelDebug, 3, &format, v...)
}
// Trace logs message as `TRACE`. Arguments handled in the mananer of `fmt.Print`.
func Trace(v ...interface{}) {
std.output(LevelTrace, 3, nil, v...)
}
// Tracef logs message as `TRACE`. Arguments handled in the mananer of `fmt.Printf`.
func Tracef(format string, v ...interface{}) {
std.output(LevelTrace, 3, &format, v...)
}
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger methods - Drop-in replacement
// for Go standard logger
//_______________________________________
// Print logs message as `INFO`. Arguments handled in the mananer of `fmt.Print`.
func Print(v ...interface{}) {
std.output(LevelInfo, 3, nil, v...)
}
// Printf logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
func Printf(format string, v ...interface{}) {
std.output(LevelInfo, 3, &format, v...)
}
// Println logs message as `INFO`. Arguments handled in the mananer of `fmt.Printf`.
func Println(format string, v ...interface{}) {
std.output(LevelInfo, 3, &format, v...)
}
// Fatal logs message as `FATAL` and call to os.Exit(1).
func Fatal(v ...interface{}) {
std.output(levelFatal, 3, nil, v...)
os.Exit(1)
}
// Fatalf logs message as `FATAL` and call to os.Exit(1).
func Fatalf(format string, v ...interface{}) {
std.output(levelFatal, 3, &format, v...)
os.Exit(1)
}
// Fatalln logs message as `FATAL` and call to os.Exit(1).
func Fatalln(format string, v ...interface{}) {
std.output(levelFatal, 3, &format, v...)
os.Exit(1)
}
// Panic logs message as `PANIC` and call to panic().
func Panic(v ...interface{}) {
std.output(levelPanic, 3, nil, v...)
panic("")
}
// Panicf logs message as `PANIC` and call to panic().
func Panicf(format string, v ...interface{}) {
std.output(levelPanic, 3, &format, v...)
panic(fmt.Sprintf(format, v...))
}
// Panicln logs message as `PANIC` and call to panic().
func Panicln(format string, v ...interface{}) {
std.output(levelPanic, 3, &format, v...)
panic(fmt.Sprintf(format, v...))
}
// SetDefaultLogger method sets the given logger instance as default logger.
func SetDefaultLogger(l *Logger) {
std = l
}
// SetLevel method sets log level for default logger.
func SetLevel(level string) error {
return std.SetLevel(level)
}
// SetPattern method sets the log format pattern for default logger.
func SetPattern(pattern string) error {
return std.SetPattern(pattern)
}
func init() {
cfg, _ := config.ParseString("log { }")
std, _ = New(cfg)
}