mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
log: Allow logging to stdout
This commit is contained in:
parent
51425b7764
commit
7ac96114c3
@ -9,10 +9,12 @@ New release of Oragono!
|
||||
|
||||
### Config Changes
|
||||
* Added `debug` section containing additional debug settings.
|
||||
* Added ability to log to `stdout` in logger methods.
|
||||
|
||||
### Security
|
||||
|
||||
### Added
|
||||
* Added ability to log to stdout.
|
||||
* Added ability to use StackImpact profiling.
|
||||
|
||||
### Changed
|
||||
|
@ -136,6 +136,7 @@ type ConnectionThrottleConfig struct {
|
||||
// LoggingConfig controls a single logging method.
|
||||
type LoggingConfig struct {
|
||||
Method string
|
||||
MethodStdout bool
|
||||
MethodStderr bool
|
||||
MethodFile bool
|
||||
Filename string
|
||||
@ -443,6 +444,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
||||
return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
|
||||
}
|
||||
logConfig.MethodFile = methods["file"]
|
||||
logConfig.MethodStdout = methods["stdout"]
|
||||
logConfig.MethodStderr = methods["stderr"]
|
||||
|
||||
// levels
|
||||
|
@ -52,7 +52,7 @@ var (
|
||||
// Manager is the main interface used to log debug/info/error messages.
|
||||
type Manager struct {
|
||||
loggers []singleLogger
|
||||
stderrWriteLock sync.Mutex
|
||||
stdoutWriteLock sync.Mutex // use one lock for both stdout and stderr
|
||||
fileWriteLock sync.Mutex
|
||||
DumpingRawInOut bool
|
||||
}
|
||||
@ -60,6 +60,7 @@ type Manager struct {
|
||||
// Config represents the configuration of a single logger.
|
||||
type Config struct {
|
||||
// logging methods
|
||||
MethodStdout bool
|
||||
MethodStderr bool
|
||||
MethodFile bool
|
||||
Filename string
|
||||
@ -85,6 +86,7 @@ func NewManager(config ...Config) (*Manager, error) {
|
||||
}
|
||||
|
||||
sLogger := singleLogger{
|
||||
MethodSTDOUT: logConfig.MethodStdout,
|
||||
MethodSTDERR: logConfig.MethodStderr,
|
||||
MethodFile: fileMethod{
|
||||
Enabled: logConfig.MethodFile,
|
||||
@ -93,7 +95,7 @@ func NewManager(config ...Config) (*Manager, error) {
|
||||
Level: logConfig.Level,
|
||||
Types: typeMap,
|
||||
ExcludedTypes: excludedTypeMap,
|
||||
stderrWriteLock: &logger.stderrWriteLock,
|
||||
stdoutWriteLock: &logger.stdoutWriteLock,
|
||||
fileWriteLock: &logger.fileWriteLock,
|
||||
}
|
||||
if typeMap["userinput"] || typeMap["useroutput"] || (typeMap["*"] && !(excludedTypeMap["userinput"] && excludedTypeMap["useroutput"])) {
|
||||
@ -165,8 +167,9 @@ type fileMethod struct {
|
||||
|
||||
// singleLogger represents a single logger instance.
|
||||
type singleLogger struct {
|
||||
stderrWriteLock *sync.Mutex
|
||||
stdoutWriteLock *sync.Mutex
|
||||
fileWriteLock *sync.Mutex
|
||||
MethodSTDOUT bool
|
||||
MethodSTDERR bool
|
||||
MethodFile fileMethod
|
||||
Level Level
|
||||
@ -177,7 +180,7 @@ type singleLogger struct {
|
||||
// Log logs the given message with the given details.
|
||||
func (logger *singleLogger) Log(level Level, logType string, messageParts ...string) {
|
||||
// no logging enabled
|
||||
if !(logger.MethodSTDERR || logger.MethodFile.Enabled) {
|
||||
if !(logger.MethodSTDOUT || logger.MethodSTDERR || logger.MethodFile.Enabled) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -226,10 +229,15 @@ func (logger *singleLogger) Log(level Level, logType string, messageParts ...str
|
||||
}
|
||||
|
||||
// output
|
||||
if logger.MethodSTDOUT {
|
||||
logger.stdoutWriteLock.Lock()
|
||||
fmt.Fprintln(colorable.NewColorableStdout(), fullStringFormatted)
|
||||
logger.stdoutWriteLock.Unlock()
|
||||
}
|
||||
if logger.MethodSTDERR {
|
||||
logger.stderrWriteLock.Lock()
|
||||
logger.stdoutWriteLock.Lock()
|
||||
fmt.Fprintln(colorable.NewColorableStderr(), fullStringFormatted)
|
||||
logger.stderrWriteLock.Unlock()
|
||||
logger.stdoutWriteLock.Unlock()
|
||||
}
|
||||
if logger.MethodFile.Enabled {
|
||||
logger.fileWriteLock.Lock()
|
||||
|
@ -49,6 +49,7 @@ Options:
|
||||
var logConfigs []logger.Config
|
||||
for _, lConfig := range config.Logging {
|
||||
logConfigs = append(logConfigs, logger.Config{
|
||||
MethodStdout: lConfig.MethodStdout,
|
||||
MethodStderr: lConfig.MethodStderr,
|
||||
MethodFile: lConfig.MethodFile,
|
||||
Filename: lConfig.Filename,
|
||||
|
@ -206,6 +206,7 @@ logging:
|
||||
# how to log these messages
|
||||
#
|
||||
# file log to given target filename
|
||||
# stdout log to stdout
|
||||
# stderr log to stderr
|
||||
method: file stderr
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user