bitrise-io/logstreamer

Name: logstreamer

Owner: Bitrise

Description: Prefixes streams (e.g. stdout or stderr) in Go

Created: 2015-04-23 22:20:22.0

Updated: 2015-05-07 10:48:17.0

Pushed: 2015-06-27 17:06:10.0

Homepage: null

Size: 118

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

logstreamer Build Status

Flattr

Prefixes streams (e.g. stdout or stderr) in Go.

If you are executing a lot of (remote) commands, you may want to indent all of their output, prefix the loglines with hostnames, or mark anything that was thrown to stderr red, so you can spot errors more easily.

For this purpose, Logstreamer was written.

You pass 3 arguments to NewLogstreamer():

This returns an interface that you can point exec.Command's cmd.Stderr and cmd.Stdout to. All bytes that are written to it are split by newline and then prefixed to your specification.

Don't forget to call Flush() or Close() if the last line of the log might not end with a newline character!

A typical usage pattern looks like this:

reate a logger (your app probably already has one)
er := log.New(os.Stdout, "--> ", log.Ldate|log.Ltime)

etup a streamer that we'll pipe cmd.Stdout to
treamerOut := NewLogstreamer(logger, "stdout", false)
r logStreamerOut.Close()
etup a streamer that we'll pipe cmd.Stderr to.
e want to record/buffer anything that's written to this (3rd argument true)
treamerErr := NewLogstreamer(logger, "stderr", true)
r logStreamerErr.Close()

xecute something that succeeds
:= exec.Command(
"ls",
"-al",

Stderr = logStreamerErr
Stdout = logStreamerOut

eset any error we recorded
treamerErr.FlushRecord()

xecute command
:= cmd.Start()
Test
 src/pkg/logstreamer/
 test

Here I issue two local commands, ls -al and ls nonexisting:

screen shot 2013-07-02 at 2 48 33 pm

Over at Transloadit we use it for streaming remote commands. Servers stream command output over SSH back to me, and every line is prefixed with a date, their hostname & marked red in case they wrote to stderr.

License

This project is licensed under the MIT license, see LICENSE.txt.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.