
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
Make Rails log beautiful!

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


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.
Thanks to awesome-print/awesome_print, a complex object is beautifully displayed. You won't be annoyed with messy long string of object description.
awesome-print/awesome_print supports more types to beautiflize.
All you need to do is rescue error, just log it Rails.logger.error e .
Rake tasks are fully logged with Beautiful::Log::TaskLogging just by adding some codes to Rakefile .
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
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
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
)
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.
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.
FAQs
Unknown package
We found that beautiful-log demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.