languages / ruby / installation / manual / generic

Ruby Manual Installation - Generic

⚠ 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 any generic Ruby app is fairly straight forward. You simply instantiate a Timber::Logger and use it as you would the Ruby standard ::Logger.

  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 global configuration 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
    # 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
    

    Note: You can set timber_logger to any global logger variable you wish. Because these are generic instructions we set it to the LOGGER constant.

  4. Finally, if you use Rack install the Timber middlewares into config.ru.

    1
    2
    3
    4
    # config.ru
    Timber::Integrations::Rack.middlewares.each do |middleware|
      use middleware
    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