All Projects → kvz → logstreamer

kvz / logstreamer

Licence: MIT license
Prefixes streams (e.g. stdout or stderr) in Go

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to logstreamer

Umbrella
"A collection of functional programming libraries that can be composed together. Unlike a framework, thi.ng is a suite of instruments and you (the user) must be the composer of. Geared towards versatility, not any specific type of music." — @loganpowell via Twitter
Stars: ✭ 2,186 (+5231.71%)
Mutual labels:  streams
Aioreactive
Async/await reactive tools for Python 3.9+
Stars: ✭ 215 (+424.39%)
Mutual labels:  streams
Kafka Ui
Open-Source Web GUI for Apache Kafka Management
Stars: ✭ 230 (+460.98%)
Mutual labels:  streams
Ni Media
NI Media is a C++ library for reading and writing audio streams.
Stars: ✭ 158 (+285.37%)
Mutual labels:  streams
Logrange
High performance data aggregating storage
Stars: ✭ 181 (+341.46%)
Mutual labels:  streams
Smallrye Mutiny
An Intuitive Event-Driven Reactive Programming Library for Java
Stars: ✭ 231 (+463.41%)
Mutual labels:  streams
Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (+234.15%)
Mutual labels:  streams
aurum
Fast and concise declarative DOM rendering library for javascript
Stars: ✭ 17 (-58.54%)
Mutual labels:  streams
Frideos flutter
An all-in-one Fllutter package for state management, reactive objects, animations, effects, timed widgets etc.
Stars: ✭ 187 (+356.1%)
Mutual labels:  streams
Multistream
A stream that emits multiple other streams one after another (streams3)
Stars: ✭ 237 (+478.05%)
Mutual labels:  streams
Bfj
MOVED TO GITLAB
Stars: ✭ 164 (+300%)
Mutual labels:  streams
Kafka Book
《Kafka技术内幕》代码
Stars: ✭ 175 (+326.83%)
Mutual labels:  streams
Mug
A small Java 8 util library, complementary to Guava (BiStream, Substring, MoreStreams, Parallelizer).
Stars: ✭ 236 (+475.61%)
Mutual labels:  streams
Vomit
😷 A minimal high order function for building user interfaces
Stars: ✭ 153 (+273.17%)
Mutual labels:  streams
module-dependents
Get the list of npm modules that depend on the specified npm module.
Stars: ✭ 15 (-63.41%)
Mutual labels:  streams
Asynquence
Asynchronous flow control (promises, generators, observables, CSP, etc)
Stars: ✭ 1,737 (+4136.59%)
Mutual labels:  streams
Devalpha Node
A stream-based approach to algorithmic trading and backtesting in Node.js
Stars: ✭ 217 (+429.27%)
Mutual labels:  streams
data examples
An example app showing different ways to pass to and share data with widgets and pages.
Stars: ✭ 56 (+36.59%)
Mutual labels:  streams
html
HTML templating and streaming response library for Service Worker-like environments such as Cloudflare Workers.
Stars: ✭ 41 (+0%)
Mutual labels:  streams
Anydlbot
An Open Source GPLv3 All-In-One Telegram Bot
Stars: ✭ 236 (+475.61%)
Mutual labels:  streams

logstreamer Build Status

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.

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:

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

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

// Execute something that succeeds
cmd := exec.Command(
	"ls",
	"-al",
)
cmd.Stderr = logStreamerErr
cmd.Stdout = logStreamerOut

// Reset any error we recorded
logStreamerErr.FlushRecord()

// Execute command
err := cmd.Start()

Test

$ cd src/pkg/logstreamer/
$ 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].