-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
55 lines (45 loc) · 1.08 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
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"bytes"
"fmt"
"log"
)
// Logger used to construct logger proccess
type Logger struct {
IsDebug bool
}
// Info used to log all INFO's messages
func (l *Logger) Info(msg ...interface{}) {
logger, buf := createNew()
msglog := fmt.Sprintf("INFO: %s", msg)
logger.Print(msglog)
fmt.Println(buf)
}
// Error used to catch any error messages
func (l *Logger) Error(msg ...interface{}) {
logger, buf := createNew()
msglog := fmt.Sprintf("Error: %s", msg)
logger.Print(msglog)
fmt.Println(buf)
}
// Debug used to log all DEBUG's message.
// This method should be active only if current process
// started with -debug (true).
func (l *Logger) Debug(msg ...interface{}) {
if l.IsDebug {
logger, buf := createNew()
msglog := fmt.Sprintf("DEBUG: %s", msg)
logger.Print(msglog)
fmt.Println(buf)
}
}
func logBuilder(isDebug bool) *Logger {
builder := new(Logger)
builder.IsDebug = isDebug
return builder
}
func createNew() (*log.Logger, *bytes.Buffer) {
var buf bytes.Buffer
logger := log.New(&buf, "Log: ", log.Ldate|log.Ltime|log.LUTC)
return logger, &buf
}