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
Related
I am working on a Rails app which they are running in AWS EC2,
this app is coming from Heroku, and this app is in Heroku is generating the logs, all show like info and verbose in the console log
However, the same app running in the AWS ec2 is not generating the same logs report as in the heroku.
They are generated in the Console log but they are not saving all log in the cloud watch or log files in rails folder.
I assume it's a more RAILS_LOG_TO_STDOUT issue on EC2? as they are built by Heroku?
config.log_formatter = ::Logger::Formatter.new
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
in the EC2 console log, this is perfect outcome log report and that what I'm looking for
but in Log report in log folder and cloudwatch show different report
Not sure where I am missing something even I have added this line and outcome still same
ActiveRecord::Base.verbose_query_logs = true
config.log_level = :info
config.log_level = :debug
Fixed as I remove two items in the gem file
gem 'rails_12factor'
gem 'rails_stdout_logging'
as it generates all the verbose, info, debug into the log files at the log folder. and it show details in the cloudwatch
My rails4 application is running with docker. It runs a rake task for fetching messages from AWS SQS.
The problem I met is that logs can't show up in a console in time. The console doesn't show anything until exception/error comes. In other words, if my application works fine, no logs come to console. But if application went wrong, all the logs(info, warn and error) come together!
I already configure the config/production.rb as blow:
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get('INFO')
config.log_level = :info
I google 'rake task log was not working', but nothing useful. Is this a rails log problem or a rake task log problem, or maybe a docker problem?
Hoping that get some advice!
Try disabling output buffering to STDOUT. You can do this by adding this line to your rake task:
$stdout.sync = true
For Rails 4.x the log level is configuration
# Enable stdout logger
config.logger = Logger.new(STDOUT)
# Set log level
config.log_level = :ERROR
The logger level is set on the logger instance from config.log_level at:
(https://github.com/rails/rails/blob/v4.2.4/railties/lib/rails/application/bootstrap.rb#L70)
I've stopped seeing my app's SQL level logs. I only see the calls for the controllers.
Haven't changed any configuration.
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
production.rb
Has anyone experience the same with Heroku?
I had the same problem.
I added
ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(ActiveRecord::Base)
to produciton.rb and it started showing the SQL queries in the log again.
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
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