Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle log drains in one-off dynos?

We're aggregating our logs to papertrail using heroku's log drains. Everything works great, except, I'm not sure how to set up logging from one-off dynos, which we use to run scripts.

I thought the drain configuration would apply to one-off dynos, but I'm not seeing the output I'd expect from jobs we run using the heroku scheduler. In an attempt to figure out what's going on, I tried running

# heroku run bash --app myapp
# babel-node
> var logger = require('bunyan/my_configured_logger');
> logger.info('YO');

I'd expect this to result in logs being shipped to papertrail, but no dice. So then, I tried the simpler command line

> logger "YO" 

and this didn't work either. So, either my tests are misguided, or drain configuration doesn't apply to one-off dynos. I think the former is more likely.

How can I test log drains (configured for a remote papertrail syslog) are working correctly?

like image 711
Paul Sanwald Avatar asked May 23 '17 17:05

Paul Sanwald


1 Answers

Try

heroku run:detached --app myapp babel-node -- -e 'var logger = require("bunyan/my_configured_logger"); logger.info("YO");'

The key here is to run the dyno in detached mode, so that stdout and stderr go to the Heroku log drain instead of the console. That means you can't run bash interactively, so you have to pass the JavaScript to evaluate on the node command line.

like image 148
Metal Fatigue Avatar answered Oct 17 '22 01:10

Metal Fatigue