-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.go
86 lines (70 loc) · 1.85 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
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
package golamb
import (
"log"
"math"
"os"
)
// LogLevel as defined in the RFC 5424 specification.
type LogLevel int
const (
// LogLevelDebug as defined in the RFC 5424 specification.
LogLevelDebug LogLevel = 0
// LogLevelInfo as defined in the RFC 5424 specification.
LogLevelInfo LogLevel = 1
// LogLevelNotice as defined in the RFC 5424 specification.
LogLevelNotice LogLevel = 2
// LogLevelWarning as defined in the RFC 5424 specification.
LogLevelWarning LogLevel = 3
// LogLevelError as defined in the RFC 5424 specification.
LogLevelError LogLevel = 4
// LogLevelCritical as defined in the RFC 5424 specification.
LogLevelCritical LogLevel = 5
// LogLevelAlert as defined in the RFC 5424 specification.
LogLevelAlert LogLevel = 6
// LogLevelEmergency as defined in the RFC 5424 specification.
LogLevelEmergency LogLevel = 7
// LogLevelSilent logs nothing.
LogLevelSilent LogLevel = math.MaxInt
)
func (l LogLevel) String() string {
switch l {
case LogLevelDebug:
return "DEBUG"
case LogLevelInfo:
return "INFO"
case LogLevelNotice:
return "NOTICE"
case LogLevelWarning:
return "WARNING"
case LogLevelError:
return "ERROR"
case LogLevelCritical:
return "CRITICAL"
case LogLevelAlert:
return "ALERT"
case LogLevelEmergency:
return "EMERGENCY"
case LogLevelSilent:
return "SILENT"
}
return "NONE"
}
// Logger is used to log messages.
type Logger interface {
Log(level LogLevel, message any)
}
// DefaultLogger logs messages to os.Stdout, which is sent to
// CloudWatch logs.
type DefaultLogger struct {
logger *log.Logger
}
// NewDefaultLogger returns the default logger.
func NewDefaultLogger() Logger {
return &DefaultLogger{
logger: log.New(os.Stdout, "", 0),
}
}
// Log implements the Logger interface.
func (l *DefaultLogger) Log(level LogLevel, message any) {
l.logger.Printf("[%s] %v\n", level, message)
}