Files
gocryptotrader/log/logger_types.go
Ryan O'Hara-Reid ac692b04f4 log: fix bug, expand test coverage and slightly optimize (#847)
* log: fix bugs expand coverage and optimise

* log: fix linter issues

* log: fix linter issue and pack methods in same file

* log: drop defer

* logger: move global check inside getfields  and remove unused test function

* logger: Increase note thanks @gloriouscode

* logger: wrap error with writer type

* logger: change variable name

* logger: change variable names and remove validsublogger func as it doesn't add functionality over a standard map call

* logs: error when unsupported output is applied on setup calls

* logs: add glorious suggestion

* logger: add protection to reduce olympic gold medal races

* logger: fix linter issues

* log: glorious niterinos
2021-11-30 16:43:27 +11:00

93 lines
2.3 KiB
Go

package log
import (
"io"
"sync"
)
const (
timestampFormat = " 02/01/2006 15:04:05 "
spacer = " | "
// DefaultMaxFileSize for logger rotation file
DefaultMaxFileSize int64 = 100
defaultCapacityForSliceOfBytes = 100
)
var (
logger = Logger{}
// FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements
FileLoggingConfiguredCorrectly bool
// GlobalLogConfig holds global configuration options for logger
GlobalLogConfig = &Config{}
// GlobalLogFile hold global configuration options for file logger
GlobalLogFile = &Rotate{}
eventPool = &sync.Pool{
New: func() interface{} {
sliceOBytes := make([]byte, 0, defaultCapacityForSliceOfBytes)
return &sliceOBytes
},
}
// LogPath system path to store log files in
LogPath string
// RWM read/write mutex for logger
RWM = &sync.RWMutex{}
)
// Config holds configuration settings loaded from bot config
type Config struct {
Enabled *bool `json:"enabled"`
SubLoggerConfig
LoggerFileConfig *loggerFileConfig `json:"fileSettings,omitempty"`
AdvancedSettings advancedSettings `json:"advancedSettings"`
SubLoggers []SubLoggerConfig `json:"subloggers,omitempty"`
}
type advancedSettings struct {
ShowLogSystemName *bool `json:"showLogSystemName"`
Spacer string `json:"spacer"`
TimeStampFormat string `json:"timeStampFormat"`
Headers headers `json:"headers"`
}
type headers struct {
Info string `json:"info"`
Warn string `json:"warn"`
Debug string `json:"debug"`
Error string `json:"error"`
}
// SubLoggerConfig holds sub logger configuration settings loaded from bot config
type SubLoggerConfig struct {
Name string `json:"name,omitempty"`
Level string `json:"level"`
Output string `json:"output"`
}
type loggerFileConfig struct {
FileName string `json:"filename,omitempty"`
Rotate *bool `json:"rotate,omitempty"`
MaxSize int64 `json:"maxsize,omitempty"`
}
// Logger each instance of logger settings
type Logger struct {
ShowLogSystemName bool
Timestamp string
InfoHeader, ErrorHeader, DebugHeader, WarnHeader string
Spacer string
}
// Levels flags for each sub logger type
type Levels struct {
Info, Debug, Warn, Error bool
}
type multiWriter struct {
writers []io.Writer
mu sync.RWMutex
}