8

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?

Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
  • The [one-off dynos docs](https://devcenter.heroku.com/articles/one-off-dynos#formation-dynos-vs-one-off-dynos) state this: “One-off dynos run attached to your terminal, with a character-by-character TCP connection for STDIN and STDOUT. This allows you to use interactive processes like a console. Since STDOUT is going to your terminal, the only thing recorded in the app’s logs is the startup and shutdown of the dyno.” Since your question in May, did you figure a way to capture those logs some other way? – Fabien Snauwaert Aug 23 '17 at 10:43

1 Answers1

5

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.

Metal Fatigue
  • 59
  • 1
  • 5