diff options
Diffstat (limited to 'plugins/logger/plugin.go')
-rw-r--r-- | plugins/logger/plugin.go | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go deleted file mode 100644 index ffbf7f5e..00000000 --- a/plugins/logger/plugin.go +++ /dev/null @@ -1,86 +0,0 @@ -package logger - -import ( - endure "github.com/spiral/endure/pkg/container" - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/plugins/config" - "go.uber.org/zap" -) - -// PluginName declares plugin name. -const PluginName = "logs" - -// ZapLogger manages zap logger. -type ZapLogger struct { - base *zap.Logger - cfg *Config - channels ChannelConfig -} - -// Init logger service. -func (z *ZapLogger) Init(cfg config.Configurer) error { - const op = errors.Op("config_plugin_init") - var err error - // if not configured, configure with default params - if !cfg.Has(PluginName) { - z.cfg = &Config{} - z.cfg.InitDefault() - - z.base, err = z.cfg.BuildLogger() - if err != nil { - return errors.E(op, errors.Disabled, err) - } - - return nil - } - - err = cfg.UnmarshalKey(PluginName, &z.cfg) - if err != nil { - return errors.E(op, errors.Disabled, err) - } - - err = cfg.UnmarshalKey(PluginName, &z.channels) - if err != nil { - return errors.E(op, errors.Disabled, err) - } - - z.base, err = z.cfg.BuildLogger() - if err != nil { - return errors.E(op, errors.Disabled, err) - } - return nil -} - -// NamedLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params. -func (z *ZapLogger) NamedLogger(name string) (Logger, error) { - if cfg, ok := z.channels.Channels[name]; ok { - l, err := cfg.BuildLogger() - if err != nil { - return nil, err - } - return NewZapAdapter(l.Named(name)), nil - } - - return NewZapAdapter(z.base.Named(name)), nil -} - -// ServiceLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params. -func (z *ZapLogger) ServiceLogger(n endure.Named) (Logger, error) { - return z.NamedLogger(n.Name()) -} - -// Provides declares factory methods. -func (z *ZapLogger) Provides() []interface{} { - return []interface{}{ - z.ServiceLogger, - } -} - -// Name returns user-friendly plugin name -func (z *ZapLogger) Name() string { - return PluginName -} - -// Available interface implementation -func (z *ZapLogger) Available() { -} |