languages / ruby / installation / manual / hanami

Ruby Manual Installation - Hanami

⚠ We highly recommend using the Ruby installer to get Timber setup in your Ruby / Hanami application. If that is not possible, please follow the instructions below.


Installing Timber into your Ruby Hanami application is fairly straight forward:

  1. In your Gemfile, add the timber gem:

    1
    2
     # Gemfile
     gem "timber", "~> 2.0"
    
  2. In your shell, run bundle install.

  3. In your config/environment.rb file install the Timber::Logger to log to your chosen IO device (HTTP, STDOUT, a file, etc). If you aren't sure, we recommend the HTTP device as it is the simplest. For a more in-depth explanation please read our HTTP, STDOUT, or Log files doc.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    # config/environment.rb
    Hanami.configure do
      # ...
      environment :development do
        timber_logger = Timber::Logger.new(STDOUT)
        timber_logger.level = :debug
        logger timber_logger
      end
    
      environment :test do
        # Silence test logging, to enable change `nil` to `STDOUT`
        timber_logger = Timber::Logger.new(nil)
        timber_logger.level = :debug
        logger timber_logger
      end
    
      environment :production do
        # --------------------------
        # PLEASE CHOOSE THE APPROPRIATE LOG DEVICE BELOW.
        # You only need one. Please delete the others you are not using.
        # --------------------------
    
        # Option 1: HTTP (recommended / simplest)
        log_device = Timber::LogDevices::HTTP.new("{{your_timber_api_key}}")
    
        # Option 2: STDOUT
        log_device = STDOUT
    
        # Option 3: A file
        log_device = Logger::LogDevice.new("log/production.log")
    
        # Now instantiate the Timber::Logger
        timber_logger = Timber::Logger.new(log_device)
        timber_logger.level = :info
        logger timber_logger
      end
    end
    
Questions?

Chat with us, just click the talk button in the bottom right of this page.

Chat with us
Sign Up

Log better and solve problems faster, today. Install in under a minute.

Sign Up