Browse Source

log: Allow logging to stdout

tags/v0.8.0
Daniel Oaks 7 years ago
parent
commit
7ac96114c3
5 changed files with 20 additions and 6 deletions
  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 View File

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

+ 2
- 0
irc/config.go View File

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

+ 14
- 6
irc/logger/logger.go View File

@@ -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()

+ 1
- 0
oragono.go View File

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

+ 1
- 0
oragono.yaml View File

@@ -206,6 +206,7 @@ logging:
206 206
         # how to log these messages
207 207
         #
208 208
         #   file    log to given target filename
209
+        #   stdout  log to stdout
209 210
         #   stderr  log to stderr
210 211
         method: file stderr
211 212
 

Loading…
Cancel
Save