mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 20:09:41 +01:00
config: Parse logger config
This commit is contained in:
parent
a982d965f1
commit
1ddeec9225
@ -116,6 +116,17 @@ type ConnectionThrottleConfig struct {
|
|||||||
Exempted []string
|
Exempted []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LoggingConfig struct {
|
||||||
|
Method string
|
||||||
|
Methods map[string]bool
|
||||||
|
Filename string
|
||||||
|
TypeString string `yaml:"type"`
|
||||||
|
Types map[string]bool `yaml:"real-types"`
|
||||||
|
ExcludedTypes map[string]bool `yaml:"real-excluded-types"`
|
||||||
|
LevelString string `yaml:"level"`
|
||||||
|
Level LogLevel `yaml:"level-real"`
|
||||||
|
}
|
||||||
|
|
||||||
type LineLenConfig struct {
|
type LineLenConfig struct {
|
||||||
Tags int
|
Tags int
|
||||||
Rest int
|
Rest int
|
||||||
@ -135,7 +146,6 @@ type Config struct {
|
|||||||
TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
|
TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
|
||||||
RestAPI RestAPIConfig `yaml:"rest-api"`
|
RestAPI RestAPIConfig `yaml:"rest-api"`
|
||||||
CheckIdent bool `yaml:"check-ident"`
|
CheckIdent bool `yaml:"check-ident"`
|
||||||
Log string
|
|
||||||
MOTD string
|
MOTD string
|
||||||
ConnectionLimits ConnectionLimitsConfig `yaml:"connection-limits"`
|
ConnectionLimits ConnectionLimitsConfig `yaml:"connection-limits"`
|
||||||
ConnectionThrottle ConnectionThrottleConfig `yaml:"connection-throttling"`
|
ConnectionThrottle ConnectionThrottleConfig `yaml:"connection-throttling"`
|
||||||
@ -154,6 +164,8 @@ type Config struct {
|
|||||||
|
|
||||||
Opers map[string]*OperConfig
|
Opers map[string]*OperConfig
|
||||||
|
|
||||||
|
Logging []LoggingConfig
|
||||||
|
|
||||||
Limits struct {
|
Limits struct {
|
||||||
AwayLen uint `yaml:"awaylen"`
|
AwayLen uint `yaml:"awaylen"`
|
||||||
ChanListModes uint `yaml:"chan-list-modes"`
|
ChanListModes uint `yaml:"chan-list-modes"`
|
||||||
@ -343,6 +355,43 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
|
if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
|
||||||
return nil, errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)")
|
return nil, errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)")
|
||||||
}
|
}
|
||||||
|
for _, logConfig := range config.Logging {
|
||||||
|
// methods
|
||||||
|
for _, method := range strings.Split(logConfig.Method, " ") {
|
||||||
|
if len(method) > 0 {
|
||||||
|
logConfig.Methods[strings.ToLower(method)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if logConfig.Methods["file"] && logConfig.Filename == "" {
|
||||||
|
return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// levels
|
||||||
|
level, exists := logLevelNames[strings.ToLower(logConfig.LevelString)]
|
||||||
|
if !exists {
|
||||||
|
return nil, fmt.Errorf("Could not translate log leve [%s]", logConfig.LevelString)
|
||||||
|
}
|
||||||
|
logConfig.Level = level
|
||||||
|
|
||||||
|
// types
|
||||||
|
for _, typeStr := range strings.Split(logConfig.TypeString, " ") {
|
||||||
|
if len(typeStr) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if typeStr == "-" {
|
||||||
|
return nil, errors.New("Encountered logging type '-' with no type to exclude")
|
||||||
|
}
|
||||||
|
if typeStr[0] == '-' {
|
||||||
|
typeStr = typeStr[1:]
|
||||||
|
logConfig.ExcludedTypes[typeStr] = true
|
||||||
|
} else {
|
||||||
|
logConfig.Types[typeStr] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(logConfig.Types) < 1 {
|
||||||
|
return nil, errors.New("Logger has no types to log")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,10 @@ import (
|
|||||||
type LogLevel int
|
type LogLevel int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// LogErr is an error value.
|
||||||
|
LogErr LogLevel = iota
|
||||||
// LogDebug represents debug messages.
|
// LogDebug represents debug messages.
|
||||||
LogDebug LogLevel = iota
|
LogDebug
|
||||||
// LogInfo represents informational messages.
|
// LogInfo represents informational messages.
|
||||||
LogInfo
|
LogInfo
|
||||||
// LogWarn represents warnings.
|
// LogWarn represents warnings.
|
||||||
@ -24,6 +26,18 @@ const (
|
|||||||
LogError
|
LogError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
logLevelNames = map[string]LogLevel{
|
||||||
|
"debug": LogDebug,
|
||||||
|
"info": LogInfo,
|
||||||
|
"warn": LogWarn,
|
||||||
|
"warning": LogWarn,
|
||||||
|
"warnings": LogWarn,
|
||||||
|
"error": LogError,
|
||||||
|
"errors": LogError,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// ClientLogger is a logger dedicated to a single client. This is a convenience class that
|
// ClientLogger is a logger dedicated to a single client. This is a convenience class that
|
||||||
// automagically adds the client nick to logged messages.
|
// automagically adds the client nick to logged messages.
|
||||||
type ClientLogger struct {
|
type ClientLogger struct {
|
||||||
@ -50,7 +64,7 @@ type Logger struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewLogger returns a new Logger.
|
// NewLogger returns a new Logger.
|
||||||
func NewLogger(config LogConfig) (*Logger, error) {
|
func NewLogger(config LoggingConfig) (*Logger, error) {
|
||||||
return nil, fmt.Errorf("Not implemented")
|
return nil, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user