Home > other >  Logs are missing from commands run via `heroku run`
Logs are missing from commands run via `heroku run`

Time:11-26

When I use heroku run to run a command, stdout and stderr only seem to go to the terminal where I ran the command. They can't be viewed with heroku logs or via logdrain.

Is there a way to get output from heroku run to be treated the same way as logs coming from, say, the scheduler?

Repro steps

In one terminal, run:

$ heroku logs --tail --app my-app

In another terminal:

$ heroku run python -c "print\(\'hi\'\)" --app my-app Running python -c print\(\'hi\'\)

What I expect:

The word "hi" should be visible in papertrail via logdrain, as well as via heroku logs -t

What actually happens:

The output goes to the terminal and it doesn't end up in logdrain or the other terminal. All I get in the logs is metadata about the process having started and exited. The actual stdout and stderr contents are missing.

CodePudding user response:

This behaviour is documented:

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.

You can use heroku run:detached if you want to output from a one-off dyno to be captured in your logs, e.g.

heroku run:detached python -c "print\(\'hi\'\)" --app my-app

Of course, this isn't a great fit for anything interactive, but then I'm not sure it makes sense to log interactive sessions.

  • Related