I'm currently working on the GCP and deployed my rails app on the GCP instance. I'm currently using https://github.com/brendeschuijmert/google-cloud-ruby/tree/master/google-cloud-logging for the compute engine.
When I use this on the rails application.
Rails.logger.info "Hello World"
works well.
But logger.warn "Hola Mundo"
is not working.
I want someone shade some light on this problem.
Thanks
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:However if
Rails.logger
is working, then you likely just need an alias likelogger = Rails.logger
to allow you to uselogger.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 fromActiveSupport::LogSubscriber
- several classes likeActionController
include childLogSubscriber
s that inherit from that module and hence have thelogger
method available to them. You can manually alias it toRails.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