mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
shorten type names to 10 chars
This commit is contained in:
parent
11d1d96d71
commit
f4f7a8afaa
6 changed files with 27 additions and 12 deletions
|
|
@ -46,8 +46,23 @@ var (
|
|||
LogWarning: "warn",
|
||||
LogError: "error",
|
||||
}
|
||||
|
||||
// these are old names for log types that might still appear in yaml configs,
|
||||
// but have been replaced in the code. this is used for canonicalization when
|
||||
// loading configs, but not during logging.
|
||||
typeAliases = map[string]string{
|
||||
"localconnect": "connect",
|
||||
"localconnect-ip": "connect-ip",
|
||||
}
|
||||
)
|
||||
|
||||
func resolveTypeAlias(typeName string) (result string) {
|
||||
if canonicalized, ok := typeAliases[typeName]; ok {
|
||||
return canonicalized
|
||||
}
|
||||
return typeName
|
||||
}
|
||||
|
||||
// Manager is the main interface used to log debug/info/error messages.
|
||||
type Manager struct {
|
||||
configMutex sync.RWMutex
|
||||
|
|
@ -100,11 +115,11 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
|||
for _, logConfig := range config {
|
||||
typeMap := make(map[string]bool)
|
||||
for _, name := range logConfig.Types {
|
||||
typeMap[name] = true
|
||||
typeMap[resolveTypeAlias(name)] = true
|
||||
}
|
||||
excludedTypeMap := make(map[string]bool)
|
||||
for _, name := range logConfig.ExcludedTypes {
|
||||
excludedTypeMap[name] = true
|
||||
excludedTypeMap[resolveTypeAlias(name)] = true
|
||||
}
|
||||
|
||||
sLogger := singleLogger{
|
||||
|
|
@ -227,7 +242,7 @@ func (logger *singleLogger) Log(level Level, logType string, messageParts ...str
|
|||
// assemble full line
|
||||
|
||||
var rawBuf bytes.Buffer
|
||||
// XXX magic number here: 9 is len("listeners"), the longest log category name
|
||||
// XXX magic number here: 10 is len("connect-ip"), the longest log category name
|
||||
// in current use. it's not a big deal if this number gets out of date.
|
||||
fmt.Fprintf(&rawBuf, "%s : %-5s : %-10s : ", time.Now().UTC().Format("2006-01-02T15:04:05.000Z"), LogLevelDisplayNames[level], logType)
|
||||
for i, p := range messageParts {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue