diff options
author | Valery Piashchynski <[email protected]> | 2020-12-21 19:42:23 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-21 19:42:23 +0300 |
commit | ee8b4075c0f836d698d1ae505c87c17147de447a (patch) | |
tree | 531d980e5bfb94ee39b03952a97e0445f7955409 /plugins/logger/plugin.go | |
parent | 0ad45031047bb479e06ce0a0f496c6db9b2641c9 (diff) |
Move plugins to the roadrunner-plugins repository
Diffstat (limited to 'plugins/logger/plugin.go')
-rw-r--r-- | plugins/logger/plugin.go | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go deleted file mode 100644 index cdd67482..00000000 --- a/plugins/logger/plugin.go +++ /dev/null @@ -1,65 +0,0 @@ -package logger - -import ( - "github.com/spiral/endure" - "github.com/spiral/roadrunner/v2/interfaces/config" - "github.com/spiral/roadrunner/v2/interfaces/log" - "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 { - err := cfg.UnmarshalKey(PluginName, &z.cfg) - if err != nil { - return err - } - - err = cfg.UnmarshalKey(PluginName, &z.channels) - if err != nil { - return err - } - - z.base, err = z.cfg.BuildLogger() - return err -} - -// DefaultLogger returns default logger. -func (z *ZapLogger) DefaultLogger() (log.Logger, error) { - return NewZapAdapter(z.base), nil -} - -// NamedLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params. -func (z *ZapLogger) NamedLogger(name string) (log.Logger, error) { - if cfg, ok := z.channels.Channels[name]; ok { - l, err := cfg.BuildLogger() - if err != nil { - return nil, err - } - return NewZapAdapter(l), nil - } - - return NewZapAdapter(z.base.Named(name)), nil -} - -// NamedLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params. -func (z *ZapLogger) ServiceLogger(n endure.Named) (log.Logger, error) { - return z.NamedLogger(n.Name()) -} - -// Provides declares factory methods. -func (z *ZapLogger) Provides() []interface{} { - return []interface{}{ - z.ServiceLogger, - z.DefaultLogger, - } -} |