mirror of
https://github.com/khorevaa/logos.git
synced 2024-11-24 08:52:19 +02:00
0b3e159306
Добавлены Named, With - клонеры логгера. Работа с контекстом
33 lines
691 B
Go
33 lines
691 B
Go
package logos
|
|
|
|
import (
|
|
"github.com/khorevaa/logos/appender"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
var StackTraceLevelEnabler = zap.NewAtomicLevelAt(zapcore.PanicLevel)
|
|
|
|
func newZapCore(config map[string]zap.AtomicLevel, appenders map[string]*appender.Appender) zapcore.Core {
|
|
|
|
zcs := make([]zapcore.Core, 0)
|
|
|
|
for name, level := range config {
|
|
|
|
if a, ok := appenders[name]; ok {
|
|
zcs = append(zcs, zapcore.NewCore(a.Encoder, a.Writer, level))
|
|
}
|
|
|
|
}
|
|
if len(zcs) == 0 {
|
|
return zapcore.NewNopCore()
|
|
}
|
|
|
|
return zapcore.NewTee(zcs...)
|
|
}
|
|
|
|
func newZapLogger(name string, core zapcore.Core, option ...zap.Option) *zap.Logger {
|
|
|
|
return zap.New(core, option...).Named(name)
|
|
}
|