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
loggerfrom 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.loggeris working, then you likely just need an alias likelogger = Rails.loggerto allow you to uselogger.warnwithout 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
loggerstems fromActiveSupport::LogSubscriber- several classes likeActionControllerinclude childLogSubscribers that inherit from that module and hence have theloggermethod available to them. You can manually alias it toRails.loggerto have it work for you wherever you are trying to invoke it.Source: https://api.rubyonrails.org/classes/ActiveSupport/LogSubscriber.html#method-c-logger