Skip to content

jonathankarsh/logstreamer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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():

  • Your *log.Logger
  • Your desired prefix ("stdout" and "stderr" prefixed have special meaning)
  • If the lines should be recorded true or false. This is useful if you want to retrieve any errors.

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.

Test

$ go 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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%