-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
42 lines (34 loc) · 817 Bytes
/
Copy pathlogger.go
File metadata and controls
42 lines (34 loc) · 817 Bytes
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
package main
import (
"fmt"
)
var logger *simpleLogger = &simpleLogger{}
const (
LevelDebug = -4
LevelInfo = 0
LevelWarn = 4
LevelError = 8
)
type simpleLogger struct {
level int
}
func (l *simpleLogger) Debug(format string, v ...any) {
if l.level <= LevelDebug {
fmt.Println("\033[90m[DEBUG]\033[0m", fmt.Sprintf(format, v...))
}
}
func (l *simpleLogger) Info(format string, v ...any) {
if l.level <= LevelInfo {
fmt.Println("\033[34m[INFO]\033[0m ", fmt.Sprintf(format, v...))
}
}
func (l *simpleLogger) Warn(format string, v ...any) {
if l.level <= LevelWarn {
fmt.Println("\033[33m[WARN]\033[0m ", fmt.Sprintf(format, v...))
}
}
func (l *simpleLogger) Error(format string, v ...any) {
if l.level <= LevelError {
fmt.Println("\033[91m[ERROR]\033[0m", fmt.Sprintf(format, v...))
}
}