-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
44 lines (37 loc) · 1.14 KB
/
logger.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
package log
import (
"fmt"
"log"
"os"
)
var stdoutLogger = log.New(os.Stdout, "INFO: ", log.LUTC|log.Ldate|log.Ltime|log.Lshortfile)
var errorLogger = log.New(os.Stderr, "ERROR: ", log.LUTC|log.Ldate|log.Ltime|log.Lshortfile)
var isDebug = false
// Error log and error to stderr
func Error(errorMessage string, args ...interface{}) error {
errorLogger.Output(3, fmt.Sprintf(errorMessage, args...))
return fmt.Errorf(errorMessage, args...)
}
// Info log info to stdout
func Info(infoMessage string, args ...interface{}) {
stdoutLogger.SetPrefix("INFO: ")
stdoutLogger.Output(2, fmt.Sprintf(infoMessage, args...))
}
// Warn log warning to stdout
func Warn(infoMessage string, args ...interface{}) {
stdoutLogger.SetPrefix("WARN: ")
stdoutLogger.Output(2, fmt.Sprintf(infoMessage, args...))
}
// Debug log debug to stdout
func Debug(infoMessage string, args ...interface{}) {
if isDebug {
stdoutLogger.SetPrefix("DEBUG: ")
stdoutLogger.Output(2, fmt.Sprintf(infoMessage, args...))
}
}
// EnableDebugMode Log debug to stdout
func EnableDebugMode() {
stdoutLogger.SetPrefix("DEBUG: ")
stdoutLogger.Output(2, "Debug mode is enabled")
isDebug = true
}