@@ -18,17 +18,17 @@ import (
18
18
logger "github.com/sirupsen/logrus"
19
19
)
20
20
21
- // LogContext contains a structured context for logging
22
- type LogContext struct {
21
+ // Context contains a structured context for logging
22
+ type Context struct {
23
23
fields logger.Fields
24
24
normalOut io.Writer
25
25
errorOut io.Writer
26
26
mutex sync.RWMutex
27
27
}
28
28
29
- // NewContext returns a LogContext with default settings
30
- func NewContext () * LogContext {
31
- var logctx LogContext
29
+ // NewContext returns a Context with default settings
30
+ func NewContext () * Context {
31
+ var logctx Context
32
32
logctx .fields = make (logger.Fields )
33
33
logctx .normalOut = os .Stdout
34
34
logctx .errorOut = os .Stderr
@@ -55,20 +55,20 @@ func SetLogLevel(logLevel string) error {
55
55
}
56
56
57
57
// WithContext is an alias for NewContext
58
- func WithContext () * LogContext {
58
+ func WithContext () * Context {
59
59
return NewContext ()
60
60
}
61
61
62
62
// AddField adds a structured field to logctx
63
- func (logctx * LogContext ) AddField (key string , value interface {}) * LogContext {
63
+ func (logctx * Context ) AddField (key string , value interface {}) * Context {
64
64
logctx .mutex .Lock ()
65
65
logctx .fields [key ] = value
66
66
logctx .mutex .Unlock ()
67
67
return logctx
68
68
}
69
69
70
70
// Tracef logs a debug message for logctx to stdout
71
- func (logctx * LogContext ) Tracef (format string , args ... interface {}) {
71
+ func (logctx * Context ) Tracef (format string , args ... interface {}) {
72
72
logger .SetOutput (logctx .normalOut )
73
73
if logctx .fields != nil && len (logctx .fields ) > 0 {
74
74
logger .WithFields (logctx .fields ).Tracef (format , args ... )
@@ -78,7 +78,7 @@ func (logctx *LogContext) Tracef(format string, args ...interface{}) {
78
78
}
79
79
80
80
// Debugf logs a debug message for logctx to stdout
81
- func (logctx * LogContext ) Debugf (format string , args ... interface {}) {
81
+ func (logctx * Context ) Debugf (format string , args ... interface {}) {
82
82
logger .SetOutput (logctx .normalOut )
83
83
if logctx .fields != nil && len (logctx .fields ) > 0 {
84
84
logger .WithFields (logctx .fields ).Debugf (format , args ... )
@@ -88,7 +88,7 @@ func (logctx *LogContext) Debugf(format string, args ...interface{}) {
88
88
}
89
89
90
90
// Infof logs an informational message for logctx to stdout
91
- func (logctx * LogContext ) Infof (format string , args ... interface {}) {
91
+ func (logctx * Context ) Infof (format string , args ... interface {}) {
92
92
logger .SetOutput (logctx .normalOut )
93
93
if logctx .fields != nil && len (logctx .fields ) > 0 {
94
94
logger .WithFields (logctx .fields ).Infof (format , args ... )
@@ -98,7 +98,7 @@ func (logctx *LogContext) Infof(format string, args ...interface{}) {
98
98
}
99
99
100
100
// Warnf logs a warning message for logctx to stdout
101
- func (logctx * LogContext ) Warnf (format string , args ... interface {}) {
101
+ func (logctx * Context ) Warnf (format string , args ... interface {}) {
102
102
logger .SetOutput (logctx .normalOut )
103
103
if logctx .fields != nil && len (logctx .fields ) > 0 {
104
104
logger .WithFields (logctx .fields ).Warnf (format , args ... )
@@ -108,7 +108,7 @@ func (logctx *LogContext) Warnf(format string, args ...interface{}) {
108
108
}
109
109
110
110
// Errorf logs a non-fatal error message for logctx to stdout
111
- func (logctx * LogContext ) Errorf (format string , args ... interface {}) {
111
+ func (logctx * Context ) Errorf (format string , args ... interface {}) {
112
112
logger .SetOutput (logctx .errorOut )
113
113
if logctx .fields != nil && len (logctx .fields ) > 0 {
114
114
logger .WithFields (logctx .fields ).Errorf (format , args ... )
@@ -118,7 +118,7 @@ func (logctx *LogContext) Errorf(format string, args ...interface{}) {
118
118
}
119
119
120
120
// Fatalf logs a fatal error message for logctx to stdout
121
- func (logctx * LogContext ) Fatalf (format string , args ... interface {}) {
121
+ func (logctx * Context ) Fatalf (format string , args ... interface {}) {
122
122
logger .SetOutput (logctx .errorOut )
123
123
if logctx .fields != nil && len (logctx .fields ) > 0 {
124
124
logger .WithFields (logctx .fields ).Fatalf (format , args ... )
@@ -127,19 +127,19 @@ func (logctx *LogContext) Fatalf(format string, args ...interface{}) {
127
127
}
128
128
}
129
129
130
- // Debugf logs a warning message without context to stdout
130
+ // Tracef logs a trace message without context to stdout
131
131
func Tracef (format string , args ... interface {}) {
132
132
logCtx := NewContext ()
133
133
logCtx .Tracef (format , args ... )
134
134
}
135
135
136
- // Debugf logs a warning message without context to stdout
136
+ // Debugf logs a debug message without context to stdout
137
137
func Debugf (format string , args ... interface {}) {
138
138
logCtx := NewContext ()
139
139
logCtx .Debugf (format , args ... )
140
140
}
141
141
142
- // Infof logs a warning message without context to stdout
142
+ // Infof logs an informational message without context to stdout
143
143
func Infof (format string , args ... interface {}) {
144
144
logCtx := NewContext ()
145
145
logCtx .Infof (format , args ... )
0 commit comments