{"id":13714317,"url":"https://github.com/kvz/logstreamer","last_synced_at":"2025-10-30T05:03:49.063Z","repository":{"id":9289170,"uuid":"11123726","full_name":"kvz/logstreamer","owner":"kvz","description":"Prefixes streams (e.g. stdout or stderr) in Go","archived":false,"fork":false,"pushed_at":"2022-10-24T07:54:23.000Z","size":17,"stargazers_count":47,"open_issues_count":0,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T15:04:26.557Z","etag":null,"topics":["go","logging","streams"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kvz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-02T11:43:48.000Z","updated_at":"2024-12-19T07:18:11.000Z","dependencies_parsed_at":"2022-09-04T22:22:15.478Z","dependency_job_id":null,"html_url":"https://github.com/kvz/logstreamer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Flogstreamer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Flogstreamer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Flogstreamer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Flogstreamer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kvz","download_url":"https://codeload.github.com/kvz/logstreamer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055276,"owners_count":21040156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","logging","streams"],"created_at":"2024-08-02T23:01:56.907Z","updated_at":"2025-10-30T05:03:49.057Z","avatar_url":"https://github.com/kvz.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"logstreamer [![Build Status][BuildStatusIMGURL]][BuildStatusURL]\n===============\n\n[BuildStatusIMGURL]:        https://secure.travis-ci.org/kvz/logstreamer.png?branch=master\n[BuildStatusURL]:           //travis-ci.org/kvz/logstreamer  \"Build Status\"\n\nPrefixes streams (e.g. stdout or stderr) in Go.\n\nIf you are executing a lot of (remote) commands, you may want to indent all of their\noutput, prefix the loglines with hostnames, or mark anything that was thrown to stderr\nred, so you can spot errors more easily.\n\nFor this purpose, Logstreamer was written.\n\nYou pass 3 arguments to `NewLogstreamer()`:\n\n - Your `*log.Logger`\n - Your desired prefix (`\"stdout\"` and `\"stderr\"` prefixed have special meaning)\n - If the lines should be recorded `true` or `false`. This is useful if you want to retrieve any errors.\n\nThis returns an interface that you can point `exec.Command`'s `cmd.Stderr` and `cmd.Stdout` to.\nAll bytes that are written to it are split by newline and then prefixed to your specification.\n\n**Don't forget to call `Flush()` or `Close()` if the last line of the log\nmight not end with a newline character!**\n\nA typical usage pattern looks like this:\n\n```go\n// Create a logger (your app probably already has one)\nlogger := log.New(os.Stdout, \"--\u003e \", log.Ldate|log.Ltime)\n\n// Setup a streamer that we'll pipe cmd.Stdout to\nlogStreamerOut := NewLogstreamer(logger, \"stdout\", false)\ndefer logStreamerOut.Close()\n// Setup a streamer that we'll pipe cmd.Stderr to.\n// We want to record/buffer anything that's written to this (3rd argument true)\nlogStreamerErr := NewLogstreamer(logger, \"stderr\", true)\ndefer logStreamerErr.Close()\n\n// Execute something that succeeds\ncmd := exec.Command(\n\t\"ls\",\n\t\"-al\",\n)\ncmd.Stderr = logStreamerErr\ncmd.Stdout = logStreamerOut\n\n// Reset any error we recorded\nlogStreamerErr.FlushRecord()\n\n// Execute command\nerr := cmd.Start()\n```\n\n## Test\n\n```bash\n$ cd src/pkg/logstreamer/\n$ go test\n```\n\nHere I issue two local commands, `ls -al` and `ls nonexisting`:\n\n![screen shot 2013-07-02 at 2 48 33 pm](https://f.cloud.github.com/assets/26752/736371/16177cf0-e316-11e2-8dc6-320f52f71442.png)\n\nOver at [Transloadit](http://transloadit.com) we use it for streaming remote commands.\nServers stream command output over SSH back to me, and every line is prefixed with a date, their hostname \u0026 marked red in case they\nwrote to stderr.\n\n## License\n\nThis project is licensed under the MIT license, see `LICENSE.txt`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkvz%2Flogstreamer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkvz%2Flogstreamer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkvz%2Flogstreamer/lists"}