Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
17 changes: 11 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,
appLog: appLog,
cfg: cfg,
}
}

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

Expand Down
14 changes: 11 additions & 3 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading