https://github.com/gamemann/go-spawn-and-output-logs-from-process
This repository shows how to spawn processes within a Go program and output their stdout and stderr pipes to a log file!
https://github.com/gamemann/go-spawn-and-output-logs-from-process
go go-lang golang logs output processes spawn stderr stdout
Last synced: 7 months ago
JSON representation
This repository shows how to spawn processes within a Go program and output their stdout and stderr pipes to a log file!
- Host: GitHub
- URL: https://github.com/gamemann/go-spawn-and-output-logs-from-process
- Owner: gamemann
- Created: 2023-05-11T06:11:42.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-11T20:10:18.000Z (over 2 years ago)
- Last Synced: 2025-02-28T12:30:02.327Z (7 months ago)
- Topics: go, go-lang, golang, logs, output, processes, spawn, stderr, stdout
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Spawn & Output Logs From Process
This is a small project to demonstrate how to spawn multiple processes from a Go program and have the Go program write their `stdout` and `stderr` lines to a log file.In this example, we have `test` and `loader` Go programs.
The `test` program outputs a random string from the `messages` variable each second to `stdout`. This is just used as a demo program.
The `loader` program runs the `test` program five times and outputs their `stdout` and `stderr` pipes to a log file in the `logs/` directory (e.g. `logs/.log`).
## Motives
I'm working on a private project which spawns processes from a Go program. However, I wanted to write the `stdout` and `stderr` pipes from these spawned processes to a file so I knew what was going on. Since the project utilized Docker which extended build/test time, I decided to write a separate open source program to achieve this goal since I could easily test things.## Building
You may use `make` via Makefile to build everything easily. Otherwise, you may use `go build loader.go` and `go build test.go` to build the Go programs.## Running
Simply run the `loader` executable to test.```bash
./loader
```**Note** - The `remove_logs.sh` file is ran on each loader start. This Bash script simply removes all log files in the `logs/` directory so we start off from a clean slate and the loader ignores any errors from executing the file.
## Credits
* [Christian Deacon](https://github.com/gamemann)