|
@@ -12,6 +12,7 @@ import (
|
12
|
12
|
"strings"
|
13
|
13
|
|
14
|
14
|
"sync"
|
|
15
|
+ "sync/atomic"
|
15
|
16
|
|
16
|
17
|
colorable "github.com/mattn/go-colorable"
|
17
|
18
|
"github.com/mgutz/ansi"
|
|
@@ -57,7 +58,7 @@ type Manager struct {
|
57
|
58
|
loggers []singleLogger
|
58
|
59
|
stdoutWriteLock sync.Mutex // use one lock for both stdout and stderr
|
59
|
60
|
fileWriteLock sync.Mutex
|
60
|
|
- loggingRawIO bool
|
|
61
|
+ loggingRawIO uint32
|
61
|
62
|
}
|
62
|
63
|
|
63
|
64
|
// LoggingConfig represents the configuration of a single logger.
|
|
@@ -95,7 +96,7 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
95
|
96
|
}
|
96
|
97
|
|
97
|
98
|
logger.loggers = nil
|
98
|
|
- logger.loggingRawIO = false
|
|
99
|
+ atomic.StoreUint32(&logger.loggingRawIO, 0)
|
99
|
100
|
|
100
|
101
|
// for safety, this deep-copies all mutable data in `config`
|
101
|
102
|
// XXX let's keep it that way
|
|
@@ -124,7 +125,7 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
124
|
125
|
fileWriteLock: &logger.fileWriteLock,
|
125
|
126
|
}
|
126
|
127
|
if typeMap["userinput"] || typeMap["useroutput"] || (typeMap["*"] && !(excludedTypeMap["userinput"] && excludedTypeMap["useroutput"])) {
|
127
|
|
- logger.loggingRawIO = true
|
|
128
|
+ atomic.StoreUint32(&logger.loggingRawIO, 1)
|
128
|
129
|
}
|
129
|
130
|
if sLogger.MethodFile.Enabled {
|
130
|
131
|
file, err := os.OpenFile(sLogger.MethodFile.Filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
|
@@ -143,9 +144,7 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
143
|
144
|
|
144
|
145
|
// IsLoggingRawIO returns true if raw user input and output is being logged.
|
145
|
146
|
func (logger *Manager) IsLoggingRawIO() bool {
|
146
|
|
- logger.configMutex.RLock()
|
147
|
|
- defer logger.configMutex.RUnlock()
|
148
|
|
- return logger.loggingRawIO
|
|
147
|
+ return atomic.LoadUint32(&logger.loggingRawIO) == 1
|
149
|
148
|
}
|
150
|
149
|
|
151
|
150
|
// Log logs the given message with the given details.
|