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
This commit is contained in:
Ryan O'Hara-Reid
2021-11-30 16:43:27 +11:00
committed by GitHub
parent f266bd14f5
commit ac692b04f4
27 changed files with 767 additions and 329 deletions

View File

@@ -10,10 +10,12 @@ const (
spacer = " | "
// DefaultMaxFileSize for logger rotation file
DefaultMaxFileSize int64 = 100
defaultCapacityForSliceOfBytes = 100
)
var (
logger = &Logger{}
logger = Logger{}
// FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements
FileLoggingConfiguredCorrectly bool
// GlobalLogConfig holds global configuration options for logger
@@ -23,9 +25,8 @@ var (
eventPool = &sync.Pool{
New: func() interface{} {
return &Event{
data: make([]byte, 0, 80),
}
sliceOBytes := make([]byte, 0, defaultCapacityForSliceOfBytes)
return &sliceOBytes
},
}
@@ -85,20 +86,6 @@ type Levels struct {
Info, Debug, Warn, Error bool
}
// SubLogger defines a sub logger can be used externally for packages wanted to
// leverage GCT library logger features.
type SubLogger struct {
name string
Levels
output io.Writer
}
// Event holds the data sent to the log and which multiwriter to send to
type Event struct {
data []byte
output io.Writer
}
type multiWriter struct {
writers []io.Writer
mu sync.RWMutex