|
@@ -52,7 +52,7 @@ var (
|
52
|
52
|
// Manager is the main interface used to log debug/info/error messages.
|
53
|
53
|
type Manager struct {
|
54
|
54
|
loggers []singleLogger
|
55
|
|
- stderrWriteLock sync.Mutex
|
|
55
|
+ stdoutWriteLock sync.Mutex // use one lock for both stdout and stderr
|
56
|
56
|
fileWriteLock sync.Mutex
|
57
|
57
|
DumpingRawInOut bool
|
58
|
58
|
}
|
|
@@ -60,6 +60,7 @@ type Manager struct {
|
60
|
60
|
// Config represents the configuration of a single logger.
|
61
|
61
|
type Config struct {
|
62
|
62
|
// logging methods
|
|
63
|
+ MethodStdout bool
|
63
|
64
|
MethodStderr bool
|
64
|
65
|
MethodFile bool
|
65
|
66
|
Filename string
|
|
@@ -85,6 +86,7 @@ func NewManager(config ...Config) (*Manager, error) {
|
85
|
86
|
}
|
86
|
87
|
|
87
|
88
|
sLogger := singleLogger{
|
|
89
|
+ MethodSTDOUT: logConfig.MethodStdout,
|
88
|
90
|
MethodSTDERR: logConfig.MethodStderr,
|
89
|
91
|
MethodFile: fileMethod{
|
90
|
92
|
Enabled: logConfig.MethodFile,
|
|
@@ -93,7 +95,7 @@ func NewManager(config ...Config) (*Manager, error) {
|
93
|
95
|
Level: logConfig.Level,
|
94
|
96
|
Types: typeMap,
|
95
|
97
|
ExcludedTypes: excludedTypeMap,
|
96
|
|
- stderrWriteLock: &logger.stderrWriteLock,
|
|
98
|
+ stdoutWriteLock: &logger.stdoutWriteLock,
|
97
|
99
|
fileWriteLock: &logger.fileWriteLock,
|
98
|
100
|
}
|
99
|
101
|
if typeMap["userinput"] || typeMap["useroutput"] || (typeMap["*"] && !(excludedTypeMap["userinput"] && excludedTypeMap["useroutput"])) {
|
|
@@ -165,8 +167,9 @@ type fileMethod struct {
|
165
|
167
|
|
166
|
168
|
// singleLogger represents a single logger instance.
|
167
|
169
|
type singleLogger struct {
|
168
|
|
- stderrWriteLock *sync.Mutex
|
|
170
|
+ stdoutWriteLock *sync.Mutex
|
169
|
171
|
fileWriteLock *sync.Mutex
|
|
172
|
+ MethodSTDOUT bool
|
170
|
173
|
MethodSTDERR bool
|
171
|
174
|
MethodFile fileMethod
|
172
|
175
|
Level Level
|
|
@@ -177,7 +180,7 @@ type singleLogger struct {
|
177
|
180
|
// Log logs the given message with the given details.
|
178
|
181
|
func (logger *singleLogger) Log(level Level, logType string, messageParts ...string) {
|
179
|
182
|
// no logging enabled
|
180
|
|
- if !(logger.MethodSTDERR || logger.MethodFile.Enabled) {
|
|
183
|
+ if !(logger.MethodSTDOUT || logger.MethodSTDERR || logger.MethodFile.Enabled) {
|
181
|
184
|
return
|
182
|
185
|
}
|
183
|
186
|
|
|
@@ -226,10 +229,15 @@ func (logger *singleLogger) Log(level Level, logType string, messageParts ...str
|
226
|
229
|
}
|
227
|
230
|
|
228
|
231
|
// output
|
|
232
|
+ if logger.MethodSTDOUT {
|
|
233
|
+ logger.stdoutWriteLock.Lock()
|
|
234
|
+ fmt.Fprintln(colorable.NewColorableStdout(), fullStringFormatted)
|
|
235
|
+ logger.stdoutWriteLock.Unlock()
|
|
236
|
+ }
|
229
|
237
|
if logger.MethodSTDERR {
|
230
|
|
- logger.stderrWriteLock.Lock()
|
|
238
|
+ logger.stdoutWriteLock.Lock()
|
231
|
239
|
fmt.Fprintln(colorable.NewColorableStderr(), fullStringFormatted)
|
232
|
|
- logger.stderrWriteLock.Unlock()
|
|
240
|
+ logger.stdoutWriteLock.Unlock()
|
233
|
241
|
}
|
234
|
242
|
if logger.MethodFile.Enabled {
|
235
|
243
|
logger.fileWriteLock.Lock()
|