Sha256: f51a286afa3321393c5ddf1aa0d3037c6e92892dc6d1bf2d2cef9da5d6ab0e5c

Contents?: true

Size: 851 Bytes

Versions: 4

Compression:

Stored size: 851 Bytes

Contents

module Sinatra
  module Log
    def log_request
      ::Herbert::AppLogger.log(request, response) if settings.log_requests
    end

    def timer_elapsed
      return (@timer_stop.to_f - @timer_start.to_f)*100
    end

    module Extension
      def self.registered(app)
        case app.log_requests
        when :db
          provider = Herbert::LoggingProviders::MongoProvider.new(app.db)
        when :stdout
          provider = Herbert::LoggingProviders::StdoutProvider.new
        else
					provider = app.log_requests
				end
        Herbert::AppLogger.provider = provider
        # Make the app automatically inject refernce to iteself into the response,
        # so Sinatra::Response::finish can manipulate it
        app.before { response.app = self; @timer_start = Time.new; }
				app.after { @timer_stop = Time.new}
			end
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
herbert-0.0.7 lib/herbert/Log.rb
herbert-0.0.6 lib/herbert/Log.rb
herbert-0.0.5 lib/herbert/Log.rb
herbert-0.0.3 lib/herbert/Log.rb