ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.88k stars 1.22k forks source link

Grape logger invalid #1528

Open piamo opened 7 years ago

piamo commented 7 years ago

in lib/grape/dsl/logger.rb, we can see:

module Grape
  module DSL
    module Logger
      include Grape::DSL::Settings

      attr_writer :logger

      # Set or retrive the configured logger. If none was configured, this
      # method will create a new one, logging to stdout.
      # @param logger [Object] the new logger to use
      def logger(logger = nil)
        if logger
          global_setting(:logger, logger)
        else
          global_setting(:logger) || global_setting(:logger, ::Logger.new($stdout))
        end
      end
    end
  end
end

Here is a problem, we can not set logger by Grape::API.logger = xxx, instead, we should call Grape::API.logger(xxx).

Seems something wrong with the attribute writter 'logger=' ?

dblock commented 7 years ago

Did you try setting this on your own API class that derives from Grape::API?

If that works then this is a feature request for a global logger setting for all API instances.

piamo commented 7 years ago

I have tried to set logger in my own API, and failed too.