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