Each project has a global logger available at Hanami.logger that can be used like this: Hanami.logger.debug "Hello"

It can be configured in config/environment.rb

# config/environment.rb
# ...

Hanami.configure do
  # ...

  environment :development do
    logger level: :info

  environment :production do
    logger level: :info, formatter: :json

    # ...

By default it uses standard output because it's a best practice that most hosting SaaS companies suggest using.

If you want to use a file, pass stream: 'path/to/file.log' as an option.

Automatic Logging

All HTTP requests, SQL queries, and database operations are automatically logged.

When a project is used in development mode, the logging format is human readable:

[bookshelf] [INFO] [2017-02-11 15:42:48 +0100] HTTP/1.1 GET 200 /books/1  451 0.018576
[bookshelf] [INFO] [2017-02-11 15:42:48 +0100] (0.000381s) SELECT "id", "title", "created_at", "updated_at" FROM "books" WHERE ("book"."id" = '1') ORDER BY "books"."id"

For production environment, the default format is JSON. JSON is parseable and more machine-oriented. It works great with log aggregators or SaaS logging products.


Prev: Projects - Rake
Next: Projects - Initializers
Looking for Lotus? We renamed the project and it's now called Hanami. Read the announcement.