-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.go
51 lines (40 loc) · 981 Bytes
/
logs.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
package main
import (
"fmt"
"time"
)
type Logger struct{}
func newLogger() *Logger {
return &Logger{}
}
func (l Logger) Log(level LogLevel, message string) {
timestamp := time.Now().Format(time.UnixDate)
if level == LogLevelInfo {
fmt.Printf("[%s] %s\n", timestamp, message)
return
}
fmt.Printf("[%s] [%s] %s\n", timestamp, level, message)
}
func (l Logger) Info(message string) {
l.Log(LogLevelInfo, message)
}
func (l Logger) Infof(format string, a ...any) {
l.Log(LogLevelInfo, fmt.Sprintf(format, a...))
}
func (l Logger) Infoln(message string) {
l.Log(LogLevelInfo, fmt.Sprintf("%s\n", message))
}
func (l Logger) Error(message string) {
l.Log(LogLevelError, message)
}
func (l Logger) Errorf(format string, a ...any) {
l.Log(LogLevelError, fmt.Sprintf(format, a...))
}
func (l Logger) Errorln(message string) {
l.Log(LogLevelError, fmt.Sprintf("%s\n", message))
}
func (l Logger) LogErr(err error) {
if err != nil {
l.Errorln(err.Error())
}
}