Bläddra i källkod

log: Allow logging to stdout

tags/v0.8.0
Daniel Oaks 7 år sedan
förälder
incheckning
7ac96114c3
5 ändrade filer med 20 tillägg och 6 borttagningar
  1. 2
    0
      CHANGELOG.md
  2. 2
    0
      irc/config.go
  3. 14
    6
      irc/logger/logger.go
  4. 1
    0
      oragono.go
  5. 1
    0
      oragono.yaml

+ 2
- 0
CHANGELOG.md Visa fil

9
 
9
 
10
 ### Config Changes
10
 ### Config Changes
11
 * Added `debug` section containing additional debug settings.
11
 * Added `debug` section containing additional debug settings.
12
+* Added ability to log to `stdout` in logger methods.
12
 
13
 
13
 ### Security
14
 ### Security
14
 
15
 
15
 ### Added
16
 ### Added
17
+* Added ability to log to stdout.
16
 * Added ability to use StackImpact profiling.
18
 * Added ability to use StackImpact profiling.
17
 
19
 
18
 ### Changed
20
 ### Changed

+ 2
- 0
irc/config.go Visa fil

136
 // LoggingConfig controls a single logging method.
136
 // LoggingConfig controls a single logging method.
137
 type LoggingConfig struct {
137
 type LoggingConfig struct {
138
 	Method        string
138
 	Method        string
139
+	MethodStdout  bool
139
 	MethodStderr  bool
140
 	MethodStderr  bool
140
 	MethodFile    bool
141
 	MethodFile    bool
141
 	Filename      string
142
 	Filename      string
443
 			return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
444
 			return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
444
 		}
445
 		}
445
 		logConfig.MethodFile = methods["file"]
446
 		logConfig.MethodFile = methods["file"]
447
+		logConfig.MethodStdout = methods["stdout"]
446
 		logConfig.MethodStderr = methods["stderr"]
448
 		logConfig.MethodStderr = methods["stderr"]
447
 
449
 
448
 		// levels
450
 		// levels

+ 14
- 6
irc/logger/logger.go Visa fil

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

+ 1
- 0
oragono.go Visa fil

49
 	var logConfigs []logger.Config
49
 	var logConfigs []logger.Config
50
 	for _, lConfig := range config.Logging {
50
 	for _, lConfig := range config.Logging {
51
 		logConfigs = append(logConfigs, logger.Config{
51
 		logConfigs = append(logConfigs, logger.Config{
52
+			MethodStdout:  lConfig.MethodStdout,
52
 			MethodStderr:  lConfig.MethodStderr,
53
 			MethodStderr:  lConfig.MethodStderr,
53
 			MethodFile:    lConfig.MethodFile,
54
 			MethodFile:    lConfig.MethodFile,
54
 			Filename:      lConfig.Filename,
55
 			Filename:      lConfig.Filename,

+ 1
- 0
oragono.yaml Visa fil

206
         # how to log these messages
206
         # how to log these messages
207
         #
207
         #
208
         #   file    log to given target filename
208
         #   file    log to given target filename
209
+        #   stdout  log to stdout
209
         #   stderr  log to stderr
210
         #   stderr  log to stderr
210
         method: file stderr
211
         method: file stderr
211
 
212
 

Laddar…
Avbryt
Spara