From 7b193a0b69550d41b955ec72f2ee2ededb1ea12f Mon Sep 17 00:00:00 2001 From: Vladimir Plakhotnikov Date: Tue, 22 Oct 2024 16:40:27 +0300 Subject: [PATCH 1/5] Draft: Separation of application and server output Signed-off-by: Plakhotnikov Vladimir --- init.go | 19 +++++++++++++------ plugin.go | 7 +++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/init.go b/init.go index c4862bc..6e9b638 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, + cfg: cfg, + appLog: appLog, } } @@ -67,8 +69,13 @@ 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)) + // Maybe use Debug for all output? We should control app logs inside app + // b.appLog.Debug(string(data)) return len(data), nil } diff --git a/plugin.go b/plugin.go index 5dd56ed..a2dc7c4 100644 --- a/plugin.go +++ b/plugin.go @@ -26,6 +26,8 @@ type Plugin struct { preparedCmd []string preparedEnvs []string + appLog *zap.Logger + log *zap.Logger factory pool.Factory } @@ -52,9 +54,10 @@ 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) + p.appLog = log.NamedLogger("app") // could be const from AppLogger or ... + // 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 +102,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)) } From 83e3af4781c105d54d9c8248a4f9b14db6f65f85 Mon Sep 17 00:00:00 2001 From: Vladimir Plakhotnikov Date: Tue, 22 Oct 2024 16:44:42 +0300 Subject: [PATCH 2/5] Draft: Separation of application and server output Signed-off-by: Plakhotnikov Vladimir --- plugin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin.go b/plugin.go index a2dc7c4..63d4ca0 100644 --- a/plugin.go +++ b/plugin.go @@ -56,6 +56,8 @@ func (p *Plugin) Init(cfg Configurer, log NamedLogger) error { p.log = log.NamedLogger(PluginName) + // let's say we always have "app" channel. + // By separating the channels, we will be able to flexibly configure the RR logs and the app logs separately. p.appLog = log.NamedLogger("app") // could be const from AppLogger or ... // here we may have 2 cases: command declared as a space-separated string or as a slice From 1c53fb7cbc67016f0dd19604f0e5b2b4af7e9046 Mon Sep 17 00:00:00 2001 From: Vladimir Plakhotnikov Date: Tue, 22 Oct 2024 20:39:23 +0300 Subject: [PATCH 3/5] Draft: Separation of application and server output Signed-off-by: Plakhotnikov Vladimir --- init.go | 4 ++-- plugin.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/init.go b/init.go index 6e9b638..211e8e1 100644 --- a/init.go +++ b/init.go @@ -73,9 +73,9 @@ func (b *command) start() error { func (b *command) Write(data []byte) (int, error) { // 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)) // Maybe use Debug for all output? We should control app logs inside app - // b.appLog.Debug(string(data)) + b.appLog.Debug(string(data)) + // b.appLog.Info(string(data)) return len(data), nil } diff --git a/plugin.go b/plugin.go index 63d4ca0..d6297de 100644 --- a/plugin.go +++ b/plugin.go @@ -27,8 +27,8 @@ type Plugin struct { preparedEnvs []string appLog *zap.Logger + log *zap.Logger - log *zap.Logger factory pool.Factory } From 340f5c61845feebad91560b99e4b21b5da9e585e Mon Sep 17 00:00:00 2001 From: Vladimir Plakhotnikov Date: Tue, 5 Nov 2024 11:12:01 +0300 Subject: [PATCH 4/5] Draft: Separation of application and server output Signed-off-by: Plakhotnikov Vladimir --- init.go | 6 ++---- plugin.go | 9 ++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/init.go b/init.go index 211e8e1..0008c08 100644 --- a/init.go +++ b/init.go @@ -21,8 +21,8 @@ type command struct { func newCommand(log *zap.Logger, appLog *zap.Logger, cfg *InitConfig) *command { return &command{ log: log, - cfg: cfg, appLog: appLog, + cfg: cfg, } } @@ -73,9 +73,7 @@ func (b *command) start() error { func (b *command) Write(data []byte) (int, error) { // 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 - // Maybe use Debug for all output? We should control app logs inside app - b.appLog.Debug(string(data)) - // b.appLog.Info(string(data)) + b.appLog.Error(string(data)) return len(data), nil } diff --git a/plugin.go b/plugin.go index d6297de..5f96379 100644 --- a/plugin.go +++ b/plugin.go @@ -32,6 +32,9 @@ type Plugin struct { 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") @@ -56,9 +59,9 @@ func (p *Plugin) Init(cfg Configurer, log NamedLogger) error { p.log = log.NamedLogger(PluginName) - // let's say we always have "app" channel. - // By separating the channels, we will be able to flexibly configure the RR logs and the app logs separately. - p.appLog = log.NamedLogger("app") // could be const from AppLogger or ... + // 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) { From be2a9cd4379cc5331d4f6038052ad00d21f5111d Mon Sep 17 00:00:00 2001 From: Vladimir Plakhotnikov Date: Thu, 7 Nov 2024 11:37:30 +0300 Subject: [PATCH 5/5] Separation of application and server output Signed-off-by: Plakhotnikov Vladimir --- init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.go b/init.go index 0008c08..39a9d6a 100644 --- a/init.go +++ b/init.go @@ -73,7 +73,7 @@ func (b *command) start() error { func (b *command) Write(data []byte) (int, error) { // 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.Error(string(data)) + b.appLog.Info(string(data)) return len(data), nil }