-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
custom_logger.go
95 lines (76 loc) · 2.67 KB
/
custom_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
87
88
89
90
91
92
93
94
95
package logger
import (
"fmt"
)
// CustomLogger defines what a user can do with a logger
type CustomLogger interface {
// Writeln writes directly to the output with no log level plus line ending
Writeln(message string)
// Write writes directly to the output with no log level
Write(message string)
// Trace level logging. Works like Sprintf.
Trace(format string, args ...interface{})
// Debug level logging. Works like Sprintf.
Debug(format string, args ...interface{})
// Info level logging. Works like Sprintf.
Info(format string, args ...interface{})
// Warning level logging. Works like Sprintf.
Warning(format string, args ...interface{})
// Error level logging. Works like Sprintf.
Error(format string, args ...interface{})
// Fatal level logging. Works like Sprintf.
Fatal(format string, args ...interface{})
}
// customLogger is a utlility to log messages to a number of destinations
type customLogger struct {
logger *Logger
name string
}
// New creates a new customLogger. You may pass in a number of `io.Writer`s that
// are the targets for the logs
func newcustomLogger(logger *Logger, name string) *customLogger {
result := &customLogger{
name: name,
logger: logger,
}
return result
}
// Writeln writes directly to the output with no log level
// Appends a carriage return to the message
func (l *customLogger) Writeln(message string) {
l.logger.Writeln(message)
}
// Write writes directly to the output with no log level
func (l *customLogger) Write(message string) {
l.logger.Write(message)
}
// Trace level logging. Works like Sprintf.
func (l *customLogger) Trace(format string, args ...interface{}) {
format = fmt.Sprintf("%s | %s", l.name, format)
l.logger.Trace(format, args...)
}
// Debug level logging. Works like Sprintf.
func (l *customLogger) Debug(format string, args ...interface{}) {
format = fmt.Sprintf("%s | %s", l.name, format)
l.logger.Debug(format, args...)
}
// Info level logging. Works like Sprintf.
func (l *customLogger) Info(format string, args ...interface{}) {
format = fmt.Sprintf("%s | %s", l.name, format)
l.logger.Info(format, args...)
}
// Warning level logging. Works like Sprintf.
func (l *customLogger) Warning(format string, args ...interface{}) {
format = fmt.Sprintf("%s | %s", l.name, format)
l.logger.Warning(format, args...)
}
// Error level logging. Works like Sprintf.
func (l *customLogger) Error(format string, args ...interface{}) {
format = fmt.Sprintf("%s | %s", l.name, format)
l.logger.Error(format, args...)
}
// Fatal level logging. Works like Sprintf.
func (l *customLogger) Fatal(format string, args ...interface{}) {
format = fmt.Sprintf("%s | %s", l.name, format)
l.logger.Fatal(format, args...)
}