How to handle log drains in one-off dynos?
Asked Answered
S

1

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?

Soult answered 23/5, 2017 at 17:46 Comment(1)
The one-off dynos docs 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?Lingam
A
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.

Aristophanes answered 16/9, 2017 at 22:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.