You can tweak its configuration in your class, but typically, the defaults should serve you well. Hanami sets up its logger differently depending on the environments:
- In
development
environment logger logs to$stdout
in:debug
mode - In
test
environment logger logs tologs/test.log
in:debug
mode - In
production
environment logger logs to$stdout
in:info
mode using:json
formatter
The logger configuration is namespaced as config.logger
and you can access it in your App
class. If you change these settings, they will be set for all environments by default.
You can fine-tune your logger on a per-environment basis using the convenient environment
method:
# config/app.rb
require "hanami"
module Bookshelf
class App < Hanami::App
environment(:development) do
end
end
end
In order to avoid having sensitive information leak to your log streams, Hanami configures log filtering to filter out the following keys:
_csrf
password
password_confirmation
If you want colorized log levels in your output, you can do so via colorize
option:
# config/app.rb
require "hanami"
module Bookshelf
class App < Hanami::App
end
end
end
You can also customize text log template to use custom colors:
Here’s what you could add to your spec_helper.rb
to have any exception that’s being logged while tests are running go to log/exceptions.log
file:
# spec/spec_helper.rb
Hanami.logger.add_backend(
stream: Hanami.app.root.join("log").join("exceptions.log"), log_if: :exception?
)
begin
raise "Oh noez"
rescue => e
Hanami.logger.error(e)