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?
Try
The key here is to run the dyno in detached mode, so that
stdout
andstderr
go to the Heroku log drain instead of the console. That means you can't runbash
interactively, so you have to pass the JavaScript to evaluate on thenode
command line.