diff --git a/init.go b/init.go index a22dd9d..ed50b88 100644 --- a/init.go +++ b/init.go @@ -13,14 +13,16 @@ import ( ) type command struct { - log *zap.Logger - cfg *InitConfig + log *zap.Logger + appLog *zap.Logger + cfg *InitConfig } -func newCommand(log *zap.Logger, cfg *InitConfig) *command { +func newCommand(log *zap.Logger, appLog *zap.Logger, cfg *InitConfig) *command { return &command{ - log: log, - cfg: cfg, + log: log, + appLog: appLog, + cfg: cfg, } } @@ -75,8 +77,11 @@ func (b *command) start() error { } } +// With these separation we do not need AppLogger plugin anymore. Just write logs to stdout/stderr func (b *command) Write(data []byte) (int, error) { - b.log.Info(string(data)) + // All output from the application does not intersect with logs from the Server plugin + // For example: destroy signal received {"timeout": 60000000000} is not necessary for logging + b.appLog.Info(string(data)) return len(data), nil } diff --git a/plugin.go b/plugin.go index 368a117..cc7ab51 100644 --- a/plugin.go +++ b/plugin.go @@ -26,10 +26,15 @@ type Plugin struct { preparedCmd []string preparedEnvs []string - log *zap.Logger + appLog *zap.Logger + log *zap.Logger + factory pool.Factory } +// AppLoggerChannel Always could depend to roadrunner-server/app-logger? +const AppLoggerChannel = "app" + // Init application provider. func (p *Plugin) Init(cfg Configurer, log NamedLogger) error { const op = errors.Op("server_plugin_init") @@ -52,9 +57,12 @@ func (p *Plugin) Init(cfg Configurer, log NamedLogger) error { return errors.E(op, errors.Init, err) } - p.log = new(zap.Logger) p.log = log.NamedLogger(PluginName) + // We always have "app" channel because we are Application Server :) + // By separating the channels, we will be able to flexibly configure the Server logs and the App logs separately. + p.appLog = log.NamedLogger(AppLoggerChannel) + // here we may have 2 cases: command declared as a space-separated string or as a slice switch len(p.cfg.Command) { // command defined as a space-separated string @@ -99,7 +107,7 @@ func (p *Plugin) Serve() chan error { errCh := make(chan error, 1) if p.cfg.OnInit != nil { - err := newCommand(p.log, p.cfg.OnInit).start() + err := newCommand(p.log, p.appLog, p.cfg.OnInit).start() if err != nil { p.log.Error("on_init was finished with errors", zap.Error(err)) // if exit_on_error is set, we should return error and stop the server