mirror of
https://github.com/bitmagnet-io/bitmagnet.git
synced 2026-08-03 01:43:48 -04:00
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package logging
|
|
|
|
import (
|
|
"github.com/bitmagnet-io/bitmagnet/internal/atomic"
|
|
"github.com/bitmagnet-io/bitmagnet/internal/logging/level"
|
|
"github.com/bitmagnet-io/bitmagnet/internal/plugin/builder"
|
|
"github.com/bitmagnet-io/bitmagnet/internal/plugin/core/config"
|
|
"github.com/bitmagnet-io/bitmagnet/internal/ref"
|
|
"github.com/bitmagnet-io/bitmagnet/pkg/plugin"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
type deps struct {
|
|
fx.In
|
|
}
|
|
|
|
var (
|
|
Ref = ref.Root.MustSub("logging")
|
|
|
|
Plugin = builder.NewPlugin(
|
|
Ref,
|
|
builder.WithDescription[deps]("Provides logging services"),
|
|
builder.WithActivation[deps](plugin.ActivationAlways),
|
|
builder.WithDependencies[deps](
|
|
config.Ref,
|
|
),
|
|
builder.WithConfig[deps](Ref.MustSub("level"), level.Param),
|
|
builder.WithFxOption[deps](
|
|
fx.Provide(
|
|
fx.Annotate(
|
|
func(lvl *atomic.Value[level.Level]) zap.AtomicLevel {
|
|
zapLevel := zap.NewAtomicLevel()
|
|
lvl.Subscribe(func(lvl level.Level) {
|
|
zapLevel.SetLevel(lvl.ToZapLevel())
|
|
})
|
|
return zapLevel
|
|
},
|
|
fx.As(new(zapcore.LevelEnabler)),
|
|
fx.As(fx.Self()),
|
|
),
|
|
fx.Annotate(
|
|
func(
|
|
zapCores []zapcore.Core,
|
|
) zapcore.Core {
|
|
return zapcore.NewTee(zapCores...)
|
|
},
|
|
fx.ParamTags(`group:"zap_cores"`),
|
|
),
|
|
func(core zapcore.Core) *zap.Logger {
|
|
opts := []zap.Option{
|
|
zap.AddStacktrace(zapcore.ErrorLevel),
|
|
zap.AddCaller(),
|
|
}
|
|
|
|
return zap.New(core, opts...)
|
|
},
|
|
),
|
|
),
|
|
)
|
|
)
|