Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find particular string in Heroku logs

I am logging some errors by doing this in my Rails app:

logger.error "MY ERROR STRING"

How can I look in heroku logs to find that line?

I know how to do heroku logs --tail and heroku logs -n 500 ,but how can I find a specific string in the logs?

like image 813
Hommer Smith Avatar asked Jul 19 '12 17:07

Hommer Smith


People also ask

How do I check heroku logs?

You can view logs with the Heroku CLI, the dashboard, your logging add-on, or in your log drain. You can't view logs for apps in Shield spaces with Private Space Logging enabled. Retrieve logs from your log drain instead.

How do I debug my heroku app?

If running heroku local does not help, run a remote shell: heroku run -a <your app name> /bin/bash , and there run npm start to see the logs and debug the issue on the Heroku server.

How do I stop heroku logs?

Just go to Papertrail > Dashboard > lower right corner > Filter logs. and papertrail will ignore all heroku/router logs.

How do I access heroku console?

Get Started with the Heroku CLI After you install the CLI, run the heroku login command. Enter any key to go to your web browser to complete login. The CLI then logs you in automatically. If you'd prefer to stay in the CLI to enter your credentials, run heroku login -i .


2 Answers

Using heroku logs -t | grep "term" is great for filtering current log events. However, Heroku retains a max of 1500 lines of log output, so even if you do heroku logs -n 1500 -t you won't see log events that occurred prior to that log window.

The better approach is to use a logging add-on like Papertrail that retains your logs for a greater period of time and makes your full log history searchable.

Of course, it also possible that the log event you think is triggering in your code isn't.

like image 195
Ryan Daigle Avatar answered Oct 20 '22 00:10

Ryan Daigle


Try putting | grep "search term" after your heroku logs -n 500 statement

so something like: heroku logs -n 500 | grep "MY ERROR STRING"

like image 24
Luke Avatar answered Oct 19 '22 23:10

Luke