-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
49 lines (41 loc) · 1.1 KB
/
logger.go
File metadata and controls
49 lines (41 loc) · 1.1 KB
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
package aprsutils
import (
"context"
"fmt"
"log"
"os"
)
// Logger construct a basic interface for logger
type Logger interface {
Debug(context.Context, ...any)
Info(context.Context, ...any)
Warn(context.Context, ...any)
Error(context.Context, ...any)
}
// NewLogger creates a new logger
func NewLogger() Logger {
logger := defaultLogger{
logger: log.New(os.Stdout, "", log.LstdFlags),
}
return logger
}
// defaultLogger is a sets of default internal logger methods
type defaultLogger struct {
logger *log.Logger
}
// Debug build Debug level log
func (l defaultLogger) Debug(ctx context.Context, args ...any) {
l.logger.Printf("[Debug] %s", fmt.Sprint(args...))
}
// Info build Info level log
func (l defaultLogger) Info(ctx context.Context, args ...any) {
l.logger.Printf("[Info] %s", fmt.Sprint(args...))
}
// Warn build Warn level log
func (l defaultLogger) Warn(ctx context.Context, args ...any) {
l.logger.Printf("[Warn] %s", fmt.Sprint(args...))
}
// Error build Error level log
func (l defaultLogger) Error(ctx context.Context, args ...any) {
l.logger.Printf("[Error] %s", fmt.Sprint(args...))
}