开发者

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(开发者_JAVA技巧"*")
=> ["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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜