Skip to content

Logging

Jrgns edited this page Sep 13, 2018 · 3 revisions

This page speaks to some of the Opinions in Ditty.

Logging in Sinatra can be deceptively difficult to set up in a consistent and elegant way. Some background reading:

Basic Setup

Ditty provides a Singleton logging interface in Ditty::Services::Logger. It responds to all the methods the standard ruby Logger class responds to, but is configurable through the Ditty::Services::Settings and supports logging to multiple endpoints. By default all logs are sent to stdout.

Configuration

Configuration for logging is done in the logging section of the config/settings.yml file. The default configuration looks as follows:

logging:
  loggers:
    - name: default
      class: Logger

This sets up one logging destinations using the vanilla Logger class. No options are passed to the class, so it just logs to stdout.

A typical configuration can look like this:

logging:
  loggers:
    - name: default
      class: Logger
    - name: files
      class: Logger
      level: WARN
      options: logs/<%= ENV['APP_ENV'] %>.log

This creates two logging destination. The default one we discussed above, as well as a logger that writes to a file under the logs folder named for the current app environment, typically, development, staging or production. Additional to that, the file logger only outputs Warning level messages and above.

How do I get this in vanilla Sinatra?

TODO

Clone this wiki locally