-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
57 lines (49 loc) · 1.65 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
package modulego
import (
"fmt"
"log"
"os"
)
// Logger is an interface that defines the methods for logging at various levels of severity.
// Implementations of Logger can be used to handle logging output for the package.
//
// Methods:
// - Debug: Logs debug-level messages, used for detailed troubleshooting information.
// - Info: Logs informational messages.
// - Warn: Logs warning messages about non-critical issues.
// - Error: Logs error messages for issues that might affect the protection.
//
// If none provider are defined, a default logger is provided by using the standard log package.
type Logger interface {
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
}
// defaultLogger implements the Logger interface by using the standard log package.
type defaultLogger struct {
logger *log.Logger
}
// NewDefaultLogger returns a new default [Logger] instance.
// This logger relies on the standard log package.
func NewDefaultLogger() Logger {
return &defaultLogger{
logger: log.New(os.Stdout, "[DataDome] ", log.LstdFlags),
}
}
// Debug method for the default logger
func (l *defaultLogger) Debug(args ...interface{}) {
l.logger.Println("DEBUG:", fmt.Sprint(args...))
}
// Info method for the default logger
func (l *defaultLogger) Info(args ...interface{}) {
l.logger.Println("INFO:", fmt.Sprint(args...))
}
// Warn method for the default logger
func (l *defaultLogger) Warn(args ...interface{}) {
l.logger.Println("WARN:", fmt.Sprint(args...))
}
// Error method for the default logger
func (l *defaultLogger) Error(args ...interface{}) {
l.logger.Println("ERROR:", fmt.Sprint(args...))
}