Easy way to merge lagger.Logger
s outputs (https://github.com/cloudfoundry/lager)
It's a io.Writer that you can pass to another logger and have its log messages redirected to a destination logger:
func ExecuteThat(logger lager.Logger) {
desinationLogger := logger.Session("execute-that")
cmd := exec.Command("command-that-outputs-lager-log-messages")
cmd.Stdout = lagregator.NewRelogger(destinationLogger)
cmd.Run()
}
All output from command-that-outputs-lager-log-messages
that was generated by a lager.Logger will
be relogged to destinationLogger
on the fly.
It's relogs a given stream:
func ExecuteThat(logger lager.Logger) {
desinationLogger := logger.Session("execute-that")
pipeW, pipeR, _ := os.Pipe()
cmd := exec.Command("command-that-outputs-lager-log-messages")
cmd.Stdout = pipeW
cmd.Run()
lagregator.RelogSream(destinationLogger, pipeR)
}
It's relogs a given bytes array:
func ExecuteThat(logger lager.Logger) {
desinationLogger := logger.Session("execute-that")
cmd := exec.Command("command-that-outputs-lager-log-messages")
output, _ := cmd.Output()
lagregator.RelogBytes(destinationLogger, output)
}