6

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

Community
  • 1
  • 1
AJP
  • 26,547
  • 23
  • 88
  • 127

3 Answers3

7

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
mu is too short
  • 426,620
  • 70
  • 833
  • 800
thenengah
  • 42,557
  • 33
  • 113
  • 157
  • Nice. Thank you Codeglot. n.b. to others, you will need to 'verify' your Heroku account to get the (free) expanded logging addon, by entering your credit card details. Heroku don't charge you any money though. – AJP Jul 24 '11 at 21:45
  • 1
    anyone know an updated answer to this? the addon doesn't exist anymore and I need to see the development / production.log output to debug my deployment! – MBHNYC Feb 22 '13 at 22:13
  • @MBHNYC see user208769's answer above. – AJP Nov 05 '14 at 09:51
4

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
Community
  • 1
  • 1
user208769
  • 2,216
  • 1
  • 18
  • 27
0

I'd also recommend using Loggly (find it in the Add Ons section on Heroku) - I'm a recent user of Heroku so I don't know if Loggly was added after these posts, but it's definitely a far snazzier, more usable, alternative to piping logs via the console.

sameers
  • 4,855
  • 3
  • 35
  • 44