If you're trying to call logger
from outside of a controller/model or some other file that is a part of Rails' structure - you will have to explicitly create a logger for yourself with:
logger = Logger.new(STDOUT) # Or wherever you want to log to
However if Rails.logger
is working, then you likely just need an alias like logger = Rails.logger
to allow you to use logger.warn
without the Rails namespace prefix. You're probably in a file that doesn't already have a helper that is aliasing that for you.
Some more digging in the API reveals that the logger
stems from ActiveSupport::LogSubscriber
- several classes like ActionController
include child LogSubscriber
s that inherit from that module and hence have the logger
method available to them. You can manually alias it to Rails.logger
to have it work for you wherever you are trying to invoke it.
Source: https://api.rubyonrails.org/classes/ActiveSupport/LogSubscriber.html#method-c-logger