Icinga/icinga-notifications

Channel: Logging output

Opened this issue · 2 comments

oxzi commented

Currently the channels are not able to log anything, which makes debugging unnecessarily difficult1.

Due to the strict request-response API logic, a new "Log" method should be introduced, which just got consumed from the RPC,
wrapping the message and logging it to icinga-notification's logger. On the channel's side, a specially configured zap logger is needed.

Footnotes

  1. I just stumbled about Icinga/icinga-notifications-web#154 again, even as I filled this issue back then..

Currently the channels are not able to log anything

Their stderr should be forwarded to the daemon logs:

logRead, logWrite, err := os.Pipe()
if err != nil {
return nil, fmt.Errorf("failed to create logRead/logWrite pipe: %w", err)
}
cmd.Stderr = logWrite
childIOPipes = append(childIOPipes, logWrite)
parentIOPipes = append(parentIOPipes, logRead)

go forwardLogs(logRead, l)

func forwardLogs(errPipe io.Reader, logger *zap.SugaredLogger) {
scanner := bufio.NewScanner(errPipe)
for scanner.Scan() {
logger.Info(scanner.Text())
}
if err := scanner.Err(); err != nil {
logger.Errorw("Failed to scan stderr line", zap.Error(err))
}
}

While not perfect (in particular, this doesn't allow to convey the severity of a message at the moment), this should be enough for debugging purposes.

oxzi commented

Thanks, I wasn't aware of this as I mostly looked into pkg/plugin and only briefly into internal/channel. Then I would suggest documenting the stderr behavior somewhere in pkg/plugin and furthermore initialize a custom zap logger in RunPlugin to allow writing same logging code as everywhere else.