summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-02-16 12:53:34 +0300
committerValery Piashchynski <[email protected]>2021-02-16 12:53:34 +0300
commitac159557f3a31e53e0c76c4196b0e42e1e71aa52 (patch)
tree3e26d5fa6f022d1cebd2da7bc9ccb832009a29f5 /plugins
parent69622100a1c95656f977638f75d8cea81afc0d4a (diff)
Update logger plugin. Now it's optional
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/logger/config.go12
-rw-r--r--plugins/logger/plugin.go14
2 files changed, 23 insertions, 3 deletions
diff --git a/plugins/logger/config.go b/plugins/logger/config.go
index bf7343c7..52594bc4 100644
--- a/plugins/logger/config.go
+++ b/plugins/logger/config.go
@@ -88,7 +88,17 @@ func (cfg *Config) BuildLogger() (*zap.Logger, error) {
zCfg.ErrorOutputPaths = cfg.ErrorOutput
}
- // todo: https://github.com/uber-go/zap/blob/master/FAQ.md#does-zap-support-log-rotation
+ // todo:
return zCfg.Build()
}
+
+// Initialize default logger
+func (cfg *Config) InitDefault() {
+ if cfg.Mode == "" {
+ cfg.Mode = "development"
+ }
+ if cfg.Level == "" {
+ cfg.Level = "debug"
+ }
+}
diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go
index 7fc464b6..08fc2454 100644
--- a/plugins/logger/plugin.go
+++ b/plugins/logger/plugin.go
@@ -20,11 +20,21 @@ type ZapLogger struct {
// 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) {
- return errors.E(op, errors.Disabled)
+ 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)
+ err = cfg.UnmarshalKey(PluginName, &z.cfg)
if err != nil {
return errors.E(op, errors.Disabled, err)
}