Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku production.log file location

I wanted to see the contents of my applications log on heroku.com so I've followed this excellent advice and have all my log contents. However I am now curious to find out where my log file actually is as "log/production.log" appears to be empty:

C:\>heroku console
Ruby console for ajpbrevx.heroku.com
>> files = Dir.glob("*")
=> ["public", "tmp", "spec", "Rakefile", "doc", "config.ru", "app", "config", "lib", "README", "Gemfile.lock", "vendor", "script", "Gemfile", "log"]
>> files = Dir.glob("log/*")
=> ["log/production.log"]
>> log_file = File.open("log/production.log", "r")
=> #<File:log/production.log>
>> log_file.each_line { |line| puts line }
=> #<File:log/production.log>
>> log_file.lstat.size
=> 0

I know I have a full log file as when I do:

heroku logs

everything is listed, so why does log/production.log not contain anything? Should I file a ticket with Heroku?

Thanks. Yours in confusion, James

like image 711
AJP Avatar asked Jul 24 '11 20:07

AJP


2 Answers

Heroku's logs are stored using logplex. You can read more about how the logging system works here but in terms of this question they do not write to your production.log file in your app because Heoku wants to keep the app's codebase as small as possible.

So if you want to view all of your logs you need to drain it to an external source.

But for watching your app and debugging you can read up to 500 lines or --tail your logs such as:

 heroku logs -n 500
 heroku addons:upgrade logging:expanded
 heroku logs --tail
like image 126
thenengah Avatar answered Nov 15 '22 11:11

thenengah


The heroku addon logging:expanded no longer exists. Some gems mask the logger output too, so for working answers see this slightly more recent stack overflow post

To summarise, the nicest solution is to add the following to your config/production.rb file:

config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get((ENV["LOG_LEVEL"] || "INFO").upcase)

Then, once you've pushed that to heroku, you can see all the logging as it happens with the following command:

heroku logs --tail
like image 37
user208769 Avatar answered Nov 15 '22 11:11

user208769