0.03
No commit activity in last 3 years
No release in over 3 years
beautiful-log provides a delightful means of displaying useful and beautiful log in Ruby on Rails application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.0

Runtime

~> 0.8.1
 Project Readme

Beautiful::Log(beta)

Gem Version

Make Rails log beautiful!

Colored log

2016-09-28 1 24 05

  • Thanks to fazibear/colorize, logged messages stand out according to their levels.
  • Messages align beautifully so you can start reading custom message instantly.

Backtrace

_2016-12-10_2_54_42

Your backtrace will be neat and understandable with Beautiful::Log::Formatter.

  • Only the file paths of your codes (app/..) are displayed and highlighted.
  • The paths are no longer verbosely long, they are shrunk to relative path from your project root.

Status Code

2016-12-10 1 30 33

2016-12-10 1 41 25

You don't miss the responses' safety any more. A log of response completion tells either your app responded correctly or not by intuitive colors. You can customize color according to status code range (hundread level e.g: 1..3.

Pretty-printd object

Thanks to awesome-print/awesome_print, a complex object is beautifully displayed. You won't be annoyed with messy long string of object description.

  • Hash

hash

  • ActiveRecord instance

ar

awesome-print/awesome_print supports more types to beautiflize.

All you need to do is rescue error, just log it Rails.logger.error e .

Logs in Rake tasks

Rake tasks are fully logged with Beautiful::Log::TaskLogging just by adding some codes to Rakefile .

Installation

Add this line to your application's Gemfile:

gem 'beautiful-log'
# or
gem 'beautiful-log', git: 'git@github.com:nogahighland/beautiful-log.git'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install beautiful-log

Usage

  • config/application.rb

    config.logger = Logger.new(config.paths["log"].first)
    config.logger.formatter = Beautiful::Log::Formatter.new
  • config/environments/development.rb

    config.log_level = :debug # set the level you need

You can change the log level from :debug to :fatal depending on staging level (develop/production/test).

  • Rakefile

    Rails.logger = Logger.new(STDOUT)
    Rails.logger.formatter = Beautiful::Log::Formatter.new
    Rails.logger.level = Logger::DEBUG # set the level you need
  • Or just include in application.rb

    module YourApplication
      class Application < Rails::Application
        # This is equivalent to code below:
        #   Rails.logger = Logger.new(config.paths['log'].first)
        #   Rails.logger.formatter = Beautiful::Log::Formatter.new
        include Beautiful::Log
        :
      end
    end

Configurations

You can customize the log appearance by passing a hash to constructor of Beautiful::Log::Formatter.

Below is a hash containing default values.

Beautiful::Log::Formatter.new(
  only_project_code: true,
  shrink_bundle_path: true,
  backtrace_ignore_paths: [],
  highlighted_line_range: 3,
  highlighted_line_styles: :cyan,
  backtrace_styles: :light_red,
  error_file_path_styles: :red,
  severity_styles: { FATAL: [:red, :swap], ERROR: :red, WARN: :light_red },
  status_code_styles: { (1..3) => [:green, :bold], 'other' => [:red, :bold] },
  occurence_line: :light_blue
)

Note

  • backtrace_ignore_paths includes bundle path if you use Bundler. The bundle path is a string Bundler.bundle_path returns, which is written in .bundle/config .

  • If you pass a hash as status_code_styles or severity_styles, those styles are merged with default values shown above.

Style specification

  • For *_styles keys, you can set a Symbol or an Array of Symbol to style a string (color, bold, underline, etc). The elements of the array are applied in order.

  • Pick your favorite color or style (called 'mode' in fazibear/colorize) below.

Requirements

  • Ruby 2.3-

Contribution

  • If you find any problematic behaviors, please make an issue with problem backtrace.
  • If you want to make changes, fork this repository, then make a pull request.

TODOs

  • Specs
  • Is is smarter to pass a proc/block to customize log style?