1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
Commit graph

4 commits

Author SHA1 Message Date
Eloy Pérez
5f95f553ab Disable monkey patch in RSpec for sinatra-contrib 2022-02-05 13:28:39 +01:00
Bo Jeanes
5e01e0db22 Limit backports usage in specs 2014-05-12 19:59:19 -07:00
Zachary Scott
fa5ccb4c4e Don't load CustomLogger by default 2014-04-04 11:35:44 +09:00
Alexey Chernenkov
36e29bbac6 Add support for custom loggers (controlled via logger setting)
CustomLogger extension allows you to define your own logger instance
using +logger+ setting. That logger then will be available
as #logger helper method in your routes and views.

=== Classic Application

To define your custom logger instance in a classic application:

    require 'sinatra'
    require 'sinatra/custom_logger'
    require 'logger'

    set :logger, Logger.new(STDOUT)

    get '/' do
      logger.info 'Some message' # STDOUT logger is used
      # Other code...
    end

=== Modular Application

The same for modular application:

    require 'sinatra/base'
    require 'sinatra/custom_logger'
    require 'logger'

    class MyApp < Sinatra::Base
      helpers Sinatra::CustomLogger

      configure :development, :production do
        logger = Logger.new(File.open("#{root}/log/#{environment}.log", 'a'))
        logger.level = Logger::DEBUG if development?
        set :logger, logger
      end

      get '/' do
        logger.info 'Some message' # File-based logger is used
        # Other code...
      end
    end
2014-03-19 13:14:01 +06:00