README
ยถ
๐ outputbuddy
Flexible output redirection with color preservation - Never lose your terminal colors when logging to files again!
outputbuddy (or ob for short) is a powerful command-line tool that lets you redirect stdout and stderr to multiple destinations simultaneously while preserving ANSI color codes and handling terminal control sequences intelligently.
โจ Features
- ๐จ Preserves Colors: Maintains ANSI color codes when redirecting to terminals
- ๐ Smart ANSI Stripping: Automatically removes ANSI codes from file outputs (configurable)
- ๐ Multiple Destinations: Route stdout/stderr to any combination of files and terminal
- ๐ Smart Defaults: Automatically logs to
buddy.logwhen no options specified - ๐ PTY Support: Full pseudo-terminal support for interactive applications
- ๐งน Progress Bar Filtering: Intelligently filters out progress bars and spinners from logs
- โก High Performance: Efficient buffering and parallel processing
- ๐ฏ Flexible Routing: Use intuitive shorthand syntax (1=stdout, 2=stderr)
๐ฆ Installation
From Source
go install github.com/zmunro/outputbuddy@latest
Using Homebrew (macOS/Linux)
brew tap zmunro/outputbuddy https://github.com/zmunro/outputbuddy
brew install outputbuddy
Pre-built Binaries
Download the latest release from the releases page.
๐ Quick Start
# Default behavior: logs to buddy.log AND shows on terminal
outputbuddy -- python script.py
# Or use the short alias
ob -- python script.py
# Custom logging: redirect both to a specific file AND show on terminal
ob 2+1=output.log 2+1 -- python script.py
# Separate stdout and stderr to different files
ob 1=out.log 2=err.log -- make
# Only log errors, but still show them on screen
ob 2=errors.log 2 -- ./my-program
๐ Usage
outputbuddy [options] -- command [args...]
Default Behavior
When no options are provided, outputbuddy automatically:
- Redirects both stdout and stderr to
buddy.log - Shows both stdout and stderr on the terminal
- Strips ANSI codes from the log file
This makes it perfect for quick debugging sessions where you want to see and log everything.
Note: The buddy.log file is ONLY created when you don't specify any routing options. As soon as you provide any routing argument (even just 1 or 2 for terminal output), outputbuddy switches to explicit routing mode and won't create buddy.log.
Options
| Option | Description |
|---|---|
1=file.log or stdout=file.log |
Redirect stdout to file |
2=file.log or stderr=file.log |
Redirect stderr to file |
2+1=file.log or stderr+stdout=file.log |
Redirect both to same file |
1 or stdout |
Show stdout on terminal |
2 or stderr |
Show stderr on terminal |
2+1 or stderr+stdout |
Show both on terminal |
--no-pty |
Disable PTY mode (use pipes instead) |
--keep-ansi |
Keep ANSI codes in file outputs |
--version, -v |
Show version information |
Examples
๐ Default Behavior
# Quick logging with default settings (logs to buddy.log)
ob -- npm test
ob -- python manage.py runserver
๐ฏ Basic Logging
# Log everything to a custom file while watching output
ob 2+1=build.log 2+1 -- cargo build --release
๐ Debug Logging
# Separate streams for debugging
ob 1=output.log 2=debug.log 1 2 -- node app.js
๐จ Preserve Colors in Files
# Keep ANSI codes for later viewing with 'less -R'
ob --keep-ansi 2+1=colored.log -- npm test
# Default behavior with ANSI preservation
ob --keep-ansi -- npm test # logs to buddy.log with colors preserved
๐คซ Silent Logging
# Log everything but show nothing on terminal
ob 2+1=silent.log -- ./batch-process.sh
# Discard output entirely
ob 2+1=/dev/null -- ./batch-process.sh
๐ซ Preventing Default buddy.log
# IMPORTANT: buddy.log is ONLY created when NO routing options are provided
# These commands will NOT create buddy.log:
# Show only on terminal (no files created)
ob 2+1 -- ./my-script.sh
# Use custom log file instead of buddy.log
ob 2+1=custom.log -- ./my-script.sh
# Separate files (no buddy.log)
ob 1=out.log 2=err.log -- make
# Even just specifying terminal output prevents buddy.log
ob 1 -- ./script.sh # Only stdout to terminal, no files
โก Development Workflow
# Perfect for development - see and log everything
ob 2+1=dev.log 2+1 -- npm run dev
๐ฎ Advanced Features
PTY Mode
By default, outputbuddy uses a pseudo-terminal (PTY) to capture output. This ensures:
- Interactive applications work correctly
- Colors are preserved in terminal output
- Terminal size changes are handled properly
Disable PTY mode with --no-pty if you need pure pipe behavior.
Smart Filtering
outputbuddy automatically filters out:
- Progress bars and spinners
- Carriage return overwrites
- Braille pattern characters
- Empty lines from progress updates
This keeps your log files clean and readable while preserving important output.
Multiple File Handling
You can redirect the same stream to multiple files:
# Log errors to both general log and error-specific log
ob 2+1=all.log 2=errors-only.log 2+1 -- ./app
๐๏ธ Building from Source
# Clone the repository
git clone https://github.com/zmunro/outputbuddy.git
cd outputbuddy
# Build
go build -o outputbuddy
# Install to $GOPATH/bin
go install
Requirements
- Go 1.18 or higher
- POSIX-compliant system (Linux, macOS, BSD)
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with creack/pty for PTY handling
- Inspired by the need for better logging in CI/CD pipelines
๐ก Tips & Tricks
Alias Setup
Add to your shell configuration:
alias ob='outputbuddy'
Default Log File
The default buddy.log file is created in the current directory when no routing options are specified:
# Quick debugging session
ob -- ./my-script.sh
# Check the log afterwards
cat buddy.log
Viewing Colored Logs
If you used --keep-ansi, view colored logs with:
less -R colored.log
# or
cat colored.log # if your terminal supports it
CI/CD Integration
Perfect for CI/CD pipelines where you need both real-time output and complete logs:
ob 2+1=ci-build.log 2+1 -- make test
# Or use default logging for quick CI runs
ob -- make test # automatically logs to buddy.log
Made with โค๏ธ by developers, for developers