reevoo / sapience-rb

Hasslefree auto-configuration for logging, metrics and exception collection.
MIT License
10 stars 0 forks source link

Grape logger not set automatically #17

Closed ionut998 closed 7 years ago

ionut998 commented 8 years ago

We noticed that when including this in the tableau_api_gateway, we had the following line in the API:

module TableauApiGateway
  class API < Grape::API
    use Sapience::Extensions::Grape::Middleware::Logging, logger: Sapience[self]
...
    get :err do
      raise "hell"
    end

    rescue_from :all do |e|
      error_response(message: e.message, status: 500)
      API.logger.error e.backtrace
    end

We were assuming that when we caught an error (e.g. by hitting /err in the code above), we would see an error logged in the Sapience format. However, we only see an error logged directly to STDOUT by the API.logger (which is a plain old Logger).

We don't want to have to go through all apps and change API.logger to Sapience.logger do we? We're not doing that when Sapience included in Rails...

jelamo commented 7 years ago

I've updated the documentation on how to avoid having to rename all calls to API.logger, just reassign it, as below:

use Sapience::Extensions::Grape::Middleware::Logging, logger: Sapience[self] API.logger = Sapience.logger