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
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.
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