Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: separation of application and server output #90

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 7 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Plugin struct {
preparedCmd []string
preparedEnvs []string

appLog *zap.Logger

log *zap.Logger
factory pool.Factory
}
Expand All @@ -52,9 +54,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)

// 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
switch len(p.cfg.Command) {
// command defined as a space-separated string
Expand Down Expand Up @@ -99,7 +104,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))
}
Expand Down
Loading