Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see request user-agent in Heroku logs

I have a Heroku app where I want to see the user-agent clients are using for their requests. When I do:

hk logs --app myapp

I see lots of interesting info, but not the HTTP request headers or the User-Agent. Is there a way to get these, or is there a way to tell Heroku to log these for future requests?

like image 739
Mike Curtiss Avatar asked Oct 25 '13 22:10

Mike Curtiss


People also ask

How do I check my Heroku application 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 read heroku errors?

Simply use heroku logs to display the last 100 lines of your logs. Heroku only saves the last 1500 lines of logs, which you can access using heroku logs -n 1500 . If you want more logging, check out Heroku add-ons like Logentries or Papertrail. Save this answer.

What is the purpose of the command heroku logs?

Log Runtime Metric LogsTo monitor load and memory usage for apps running in Dynos, Heroku Labs offers a feature called “log-runtime-metrics.” The CLI command $ heroku logs --tail can be used to view statistics about memory and swap use, as well as load averages, all of which flow into the app's log stream.

What is Heroku application error?

"Application Error" or similar is always caused by your own application code. Routing errors will normally only surface themselves within the logs of your application. To track this kind of issue down you should look at your logs: $ heroku logs --tail --app your_app_name.


1 Answers

To customize logs messages you will have to implement specific logger in your application, like @RobinGower suggests in comments to your question. It's not a common task, so there is no 1-click solutions for this.

Though if you have common goal for why you want to see user-agent - solution could be easy, for example:

  • if you want to see for which browsers some specific error happens, you can use "rollbar" or simialr error logging heroku's extension

enter image description here

  • if you want to do some calculations on which browsers used to reach different pages, you may be interested in embedding to you application analytics system, like "Google analytics":

enter image description here

like image 52
Daniel Garmoshka Avatar answered Oct 28 '22 04:10

Daniel Garmoshka