-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
52 lines (41 loc) · 1.19 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
package coda
import "log"
// Logger defines the interface for custom logging implementations for coda.
type Logger interface {
// Info logs an informational message
Info(str string)
// Error logs an error message
Error(str string)
}
// StdLogger is a logger that adapts Logger to a *log.Logger from the standard library.
type StdLogger struct {
l *log.Logger
}
var _ Logger = &StdLogger{}
// NewStdLogger creates a new Logger that wraps the standard library's log.Logger.
// It provides a simple way to integrate with Go's built-in logging.
//
// Example:
//
// logger := coda.NewStdLogger(log.Default())
// sd := coda.NewShutdown(coda.WithShutdownLogger(logger))
func NewStdLogger(logger *log.Logger) Logger {
return &StdLogger{
l: logger,
}
}
func (l *StdLogger) Info(str string) {
l.l.Println("info: ", str)
}
func (l *StdLogger) Error(str string) {
l.l.Println("error: ", str)
}
// NoopLogger is a logger that discards all output.
type NoopLogger struct{}
var _ Logger = &NoopLogger{}
// NewNoopLogger creates a new NoopLogger. This logger discards all output.
func NewNoopLogger() Logger {
return &NoopLogger{}
}
func (*NoopLogger) Info(_ string) {}
func (*NoopLogger) Error(_ string) {}