Skip to content

Commit

Permalink
- Add function to set std logger in golang (instead to return it with…
Browse files Browse the repository at this point in the history
… GetLogger)
  • Loading branch information
Nicolas JUHEL committed Apr 16, 2020
1 parent d4f40fa commit f9fca93
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions njs-logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ func GetLogger(lvl Level, logFlags int, msgPrefixPattern string, msgPrefixArgs .
return log.New(GetIOWriter(lvl, msgPrefixPattern, msgPrefixArgs...), "", logFlags)
}

// GetLogger force the default golang log.logger instance linked with this main logger
//
// This function is useful to keep the format, mode, color, output... same as current config
/*
msgPrefixPattern a pattern prefix to identify or comment all message passed throw this log.logger instance
msgPrefixArgs a list of interface to apply on pattern with a fmt function
*/
func SetStdLogger(lvl Level, logFlags int, msgPrefixPattern string, msgPrefixArgs ...interface{}) {
log.SetOutput(GetIOWriter(lvl, msgPrefixPattern, msgPrefixArgs...))
log.SetPrefix("")
log.SetFlags(logFlags)
}

// AddGID Reconfigure the current logger to add or not the thread GID before each message.
func AddGID(enable bool) {
enableGID = enable
Expand Down

0 comments on commit f9fca93

Please sign in to comment.