Delayed Jobs isn't logging on Heroku - ruby-on-rails

I managed to log into a custom log file using this configuration:
Delayed::Worker.logger =
ActiveSupport::BufferedLogger.new("log/#{Rails.env}_delayed_jobs.log", Rails.logger.level)
It's working locally. I can see the file change and all the logs I want.
But the problem is that when I deploy to Heroku and run the job, and try to read the contents of the file through the console, I don't get the expected results.
irb(main):070:0* File.read('/app/log/production_delayed_jobs.log')
=> "# Logfile created on 2013-06-20 08:36:43 +0000 by logger.rb/25413\n"
Note that I set the loggin level to :debug in production. In config/environments/production.rb I have this configuration:
config.log_level = :debug

Basically #yoav is right, you can't write to your own log files on heroku (no file system access). what you can do is described in the heroku logs right here: https://devcenter.heroku.com/articles/logging#writing-to-your-log

Related

Rails | How to see live server log in production?

How to see the live server log in production like it is shown in development?
My app is on digitalOcean, if that helps. I am using unicorn as my production server.
When I do tail -f log/production.log, I can just see some migration info like this, but not the live requests info along with the SQL queries being run.
Also in my production.rb, I changed config.log_level to :debug
Try adding these lines of code into config/environments/production.rb:
Rails.logger = Logger.new(STDOUT)
config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
Reference:
This article for more info on logger

How do I get Rails 4.1.1 to write to the log file in Windows?

Log output is going to the console, but I want it to go to the log file also. Windows console is not so good for keeping track of separate requests. If I delete the file, it will create log/development.log, but it doesn't write to it except for one line! ("Logfile created on...")
Here is my config/environment/development.rb (I've tried several combinations of commenting/uncommenting)
config.log_level = :debug
# Rails.logger = Logger.new("log/development.log")
config.logger = Logger.new("log/development.log")
Here is my environment
C:\Users\Chloe\workspace\Tyger>rails runner 'puts Rails.env'
DL is deprecated, please use Fiddle
Vanity: loading experiments from C:/Users/Chloe/workspace/Tyger/experiments
Vanity: loading metrics from C:/Users/Chloe/workspace/Tyger/experiments/metrics
development
Reference: http://guides.rubyonrails.org/debugging_rails_applications.html#the-logger

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.

Heroku debugging

I am building an application with Heroku and having some problems.
I want to debug some content like I do with rails server:
logger.debug '...'
How can I do that in Heroku, so I can see the debugging in heroku logs? (or anything else..)
Thanks!
Details here: http://devcenter.heroku.com/articles/logging
Also make sure you set the right Logging level for your Rails app:
http://blog.sethladd.com/2005/11/adjust-log-level-in-ruby-on-rails.html
The Cedar stack in Heroku does not appear to be responsive to the LOG_LEVEL config (env) variable that works for previous stacks (I use the logging:expanded addon). I tried setting LOG_LEVEL to both debug and DEBUG without success.
Only by setting config.log_level = :debug in config/environments/production.rb am I able to see the output of 'logger.debug'.
Been fighting with this for a long time, solution is nice and simple:
Set in production.rb instead of
config.log_level = :debug
place:
config.logger = Logger.new(STDOUT)
config.logger.level = Logger::DEBUG
and you get the full logging output.
heroku logs on your command line will give you the logs for the current app. If you have expanded logging turned on you can tail this output
Using Rails 3.2, we made this configurable by modifying config/environments/{environment}.rb to drive it from an environment variable:
config.log_level = ENV["LOG_LEVEL"].to_sym if ENV["LOG_LEVEL"]
Then, we can modify the Heroku config variable to change it:
heroku config:set LOG_LEVEL=debug --app <app name>
This lets us easily log more or less as needed.
This worked for me:
heroku config:set LOG_LEVEL=debug
To write to your logs on Heroku, instead of using logger.debug "..." simply use puts:
puts "..."
You don't even need to set the config.log_level setting in config/environments/production.rb.
See the docs here.
config.log_level = ENV['APP_LOG_LEVEL'] ? ENV['APP_LOG_LEVEL'].to_sym : :error

Why is my deployed rails app writing to a production.log file?

Where in my configuration does it say to write to a production.log file?
What is the best practise for this, to log critical errors only I'm guessing, how would I do that?
By default the log file is a convention from the environment name. So in production environment the log will be named production.log, in development it is called development.log.
You can override the log file name and the log level for production in config/environments/production.rb by putting the lines below.
config.log_level = :error # this will the rails to log error only in production
config.log_path = log/something_else.log # defaults to log/#{environment}.log

Resources