๐ŸŒˆ log-pretty

Transform raw logs into beautiful, human-readable output โ€” instantly.

Gem Version License: MIT Ruby Tests


# 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

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.

  1. Fork the repository
  2. Create your branch: git checkout -b feature/my-feature
  3. Add tests for your changes
  4. Run bundle exec rspec โ€” all tests must pass
  5. Submit a Pull Request

Made with โค๏ธ by Brijesh S A