Rails production log level - ruby-on-rails

I am using rails 4.2.6. And the log_level is :warn for production environment. But when I tail -f the production log file on server I am seeing that it logs at :info level. So the log file is getting bigger in a short time. I am really creazy. Is there any clue that how can I solve this issue?

I find the solution. The solution is this: config.action_view.logger = nil.

Related

Rails not logging requests

I'm utterly stumped as to why I'm not able to see the Rails controller outputs in my development log. I've spent days beating my head against a wall trying to figure this out and I'm not sure what else to try.
Setup: Rails 5.2.3 app running ruby 2.6.3 via docker-compose.
It started with me not being able to see my app logs when running docker logs <container-name>. However, I soon realized that I was able to see the output from puma starting and a shell script that ran rake tasks that the issue might be with rails.
To help assist with finding the issue:
Tore down and rebuilt the docker environment, several times
Stopped writing via STDOUT in favor of logs/development.log
Disabled lograge and elastic-apm, just in case
Reverted my development.rb config back to what's generated with a rails new
Followed the suggestions here
However, when running the rails console via docker exec -it <container-name>:
Running Rails.logger.level returns 2 which is warn, despite the default logging level being dev
I'm able to see log output when running Rails.logger.warn 'foo'
After setting Rails.logger.level = 0 I'm able to see output when running Rails.logger.debug 'foo'
I tried setting the value explicitly as config.log_level = :debug in development.rb yet it still set itself to the warn level.
However, I'm still not able to see any logs when navigating the application. Any thoughts?
Ugh. I feel like the biggest schmuck but I've figured out the issue.
I went back though source-control to see what has changed recently. In addition to the elastic-apm gem, I also added the Unleash gem.
I went to check out it's configuration and it looks like following their recommenced configuration causes logging to break. The line that was specifically causing offense was in the unleash initializer setting config.logger = Rails.logger

Rails logs in staging are only writing to my log files. How do I get them to log to STDout or papertrail?

I currently have this issue that when there's an error, the logs in my terminal aren't informative. The logs are only writing to the log files but my terminal output doesn't show anything. This was super confusing. How do I change this?
What is the Rails default behavior anyway when it comes to logging?
In Rails, by default, each log is created under Rails.root/log/ and the log file is named after the environment in which the application is running.
But if you want to change you can specify something like below in config/application.rb which would throw out logs on STDOUT.
config.logger = Logger.new(STDOUT)
See the Rails guides for more info.
What I usually found easy was to tail the log on console like $ tail -f log/development.log and force/see the output of log file on console.

Production log file is not updating, Rails 4.16 + Passanger

I have Rails 4.1.6 app on Passanger (Shared host).
Quite a while I worked in development, but now I switched to production.
In environment.rb:
ENV['RAILS_ENV'] = 'production'
then touch tmp/restart.txt to restart server.
When accessing my app I am receiving Internal Server Error. It is ok. I expected that, so I went to production.log to see what caused error, but it was blank.
Before I switched to production, development.log file showed all logs without problem.
What I tried:
1) Deleted production.log and restarted server. After folder reload production.log was created again. Permisions: 0664 the same as development.log
2) Added lines and restarted server :
config.log_level = :debug
RAILS_DEFAULT_LOGGER = Logger.new('log/production.log')
3) Double checked if current environment is production.
4) Manually wrote in production.log using console command:
Rails.logger.error('TEST ERROR')
After this command I saw this error message in production.log file.
Thanks in advance for any help.
Finally, I solved my problem.
Bassically, there wasn't any problem with production.log , problem was that my Rails 4 app didn't really start. I received Apache error:
Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`
So I solved above error with help of this answer
And now Rails 4 app starts and production.log updates without problem.

500 in Heroku logs, but no error details from Rails (even with rails_12factor)

When I tail the logs and hit my app, I have heroku[router] telling me I received a 500, and the app shows the usual "We're sorry, but something went wrong" message... but there are no additional details from Rails in the logs to tell me what is causing the 500.
I've read a couple of other threads that asked about this but they mostly end with people suggesting to do a rake:db migrate which fixed the error but there's no further discussion about the logging unfortunately. (And yes I'm sure there's no pending migrations 😄)
I have the rails_12factor gem installed
I've tried setting config.log_level = :debug in production.rb
I've tried creating a config variable of LOG_LEVEL set to DEBUG (which should supersede the config setting)
I've set $stdout.sync = true in config.ru as suggested here
What am I missing?
As an aside, have tried re-producing my actual problem locally with a backup of the database being used with Heroku but I can't reproduce it, so I'm finally forced to get to the bottom of this logging problem.
I first just got this to work by manually adding:
config.logger = Logger.new(STDOUT)
to production.rb but that obscured the real issue...
RACK_ENV and RAILS_ENV were both set to staging while I had the gem loading in the :production set... So although Heroku told me it was using the rails_12factor gem when the instance started, it wasn't really (I assumed it wouldn't be listed there if it wasn't a production environment, wrong assumption!)
staging.rb was loading production.rb which is why setting STDOUT there worked, thus confusing the issue further.
Thanks for the replies, and hope this helps someone else in future - go check your config variables and/or change where the gem is being loaded! :)
Debugging errors on heorku can get difficult most of the time.
For people facing a similar problem I suggest using PaperTrail heroku add-on for logging, It is free upto a certain limit.
It is realtime and provides with searching of logs, events hooks, mailing alerts etc. facilities. You will never have trouble debugging errors on heroku.
You can simply install it using the heroku cli command.
heroku addons:create papertrail

Rails: How to debug in production environment?

I've deployed to a VPS, but when visiting to my site, message shows:
We're sorry but something went wrong.
How could I start to debug?
I've deployed this commit successfully to heroku before. And before pushing to VPS, the site was running well.
I tried to see the log/production.log, but it only says Connecting to database specified by database.yml
Start with logs. Set more verbose log level to see what happens: set config.log_level = :debug in your config/environments/production.rb
More general, try something like errbit to see details about your production errors.

Resources