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?
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.
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.
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.
"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.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With