-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
60 lines (55 loc) · 1.61 KB
/
log.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
package log
import "strings"
const (
DEBUG = iota
INFO
WARN
ERR
FATAL
)
// LoggerConfiguration represents the configuration for a logger instance.
type LoggerConfiguration struct {
// Prefix is a string that is prepended to each log message.
Prefix string
// Verbosity is an integer representing the level of verbosity for the logger.
// It should be one of the constants defined above (DEBUG, INFO, WARN, ERR, or FATAL).
Verbosity int
}
// Logger is an interface that defines the methods that a logger should implement.
type Logger interface {
// Debug logs a message at the Debug level.
Debug(string, ...interface{})
// Info logs a message at the Info level.
Info(string, ...interface{})
// Warn logs a message at the Warn level.
Warn(string, ...interface{})
// Err logs a message at the Err level.
Err(string, ...interface{})
// Panic logs a message at the Panic level and then panics.
Panic(string, ...interface{})
// Fatal logs a message at the Fatal level and then calls os.Exit(1).
Fatal(string, ...interface{})
// SetVerbosity sets the verbosity level of the logger.
SetVerbosity(string)
// Shutdown closes any resources used by the logger.
Shutdown() error
}
// GetVerbosityFromString converts a string representation of a verbosity level
// to the corresponding integer constant.
// If the input string is not recognized, the function returns Warn.
func GetVerbosityFromString(verbosity string) int {
switch strings.ToLower(verbosity) {
case "debug":
return DEBUG
case "info":
return INFO
case "warn":
return WARN
case "err":
return ERR
case "fatal":
return FATAL
default:
return WARN
}
}