# Before โ raw JSON log
{"timestamp":"2026-04-24T22:38:51Z","level":"error","message":"DB timeout","code":503,"retry":true}
# After โ log-pretty output
2026-04-24T22:38:51Z [ERROR]
Message: DB timeout
Code: 503
Retry: true
โจ Features
| Feature | Description | ||
|---|---|---|---|
| ๐จ | Colorized levels | DEBUG=cyan ยท INFO=green ยท WARN=yellow ยท ERROR=red ยท FATAL=magenta |
|
| ๐ | Structured output | Indented, field-by-field display โ scan logs at a glance | |
| ๐ | Auto-detect format | Parses JSON and plain-text logs automatically | |
| ๐ง | CLI pipe tool | `tail -f app.log \ | log-pretty` โ works anywhere |
| ๐ | Ruby library | Embed directly in your Ruby app or Rack middleware | |
| โก | Minimal footprint | Only one runtime dependency: rainbow |
๐ฆ Installation
Via RubyGems (recommended)
gem install pretty_logs
Via Bundler
Add to your Gemfile:
gem 'pretty_logs'
Then:
bundle install
From Source
git clone https://github.com/brijeshsajeev/log-pretty
cd log-pretty/pretty_logs
bundle install
bundle exec rake install
๐ CLI Usage
log-pretty reads from stdin and writes prettified output to stdout.
# Pipe a file
log-pretty < app.log
# Tail live logs
tail -f production.log | log-pretty
# Pipe from a running process
docker logs -f my-container | log-pretty
rails server 2>&1 | log-pretty
Options
| Flag | Description |
|---|---|
-f, --format FORMAT |
Force format: auto (default), json, plain |
-s, --simple |
Single-line output instead of structured |
-c, --[no-]color |
Enable/disable colors (default: enabled) |
-h, --help |
Show help |
Examples
JSON log:
echo '{"timestamp":"2026-04-24T22:38:51Z","level":"info","message":"User logged in","user_id":123}' | log-pretty
# 2026-04-24T22:38:51Z [INFO]
# Message: User logged in
# User_id: 123
Plain-text log:
echo '2026-04-24T22:38:51Z [ERROR] Connection timeout' | log-pretty
# 2026-04-24T22:38:51Z [ERROR]
# Message: Connection timeout
Simple single-line output:
tail -f app.log | log-pretty --simple
# 2026-04-24T22:38:51Z [INFO] Application started
# 2026-04-24T22:38:52Z [WARN] High memory usage
No colors (for log files / CI):
log-pretty --no-color < app.log > cleaned.log
๐ Ruby Library Usage
require 'pretty_logs'
formatter = PrettyLogs::Formatter.new(structured: true)
# Format a hash directly
entry = {
timestamp: "2026-04-24T22:38:51Z",
level: "info",
message: "Processing request",
request_id: "abc123",
duration_ms: 42
}
puts formatter.format(entry)
# 2026-04-24T22:38:51Z [INFO]
# Message: Processing request
# Request_id: abc123
# Duration_ms: 42
# Parse and format a JSON log line
json_line = '{"level":"error","message":"Database error","code":500}'
parsed = PrettyLogs::Parsers::JsonParser.parse(json_line)
puts formatter.format(parsed)
# Parse and format a plain-text log line
plain_line = "2026-04-24T22:38:51Z [WARN] High memory usage"
parsed = PrettyLogs::Parsers::PlainTextParser.parse(plain_line)
puts formatter.format(parsed)
๐ Supported Log Formats
JSON Logs
Any valid JSON object. Recognized fields:
| Field | Description |
|---|---|
timestamp |
ISO 8601 timestamp |
level |
Log level (debug, info, warn, error, fatal) |
message |
Log message |
| any other field | Displayed as additional structured data |
Plain-Text Logs
YYYY-MM-DDTHH:MM:SS[.mmm][Z|ยฑHH:MM] [LEVEL] Message text
Examples:
2026-04-24T22:38:51Z [INFO] Application started
2026-04-24T22:38:51.123Z [ERROR] Connection failed
2026-04-24T22:38:51.000+05:30 [DEBUG] Cache miss for key=user:42
๐จ Log Level Colors
| Level | Color | Example use |
|---|---|---|
DEBUG |
Cyan | Low-level diagnostics |
INFO |
Green | Normal operations |
WARN / WARNING |
Yellow | Something may need attention |
ERROR |
Red | Something failed |
FATAL |
Magenta | Critical failure |
๐ง CI / Automation Usage
Disable colors for clean output in CI pipelines:
# GitHub Actions, Jenkins, etc.
cat build.log | log-pretty --no-color
# Or via env (Rainbow respects NO_COLOR)
NO_COLOR=1 log-pretty < app.log
๐ Development
git clone https://github.com/brijeshsajeev/log-pretty
cd log-pretty/pretty_logs
bundle install
bundle exec rspec # Run test suite
bundle exec log-pretty # Test CLI manually
๐งช Testing
bundle exec rspec
14 examples, 0 failures โ
๐ License
MIT License ยฉ 2026 Brijesh S A
๐ค Contributing
Bug reports and pull requests are welcome on GitHub.
- Fork the repository
- Create your branch:
git checkout -b feature/my-feature - Add tests for your changes
- Run
bundle exec rspecโ all tests must pass - Submit a Pull Request
Made with โค๏ธ by Brijesh S A