View logs for a heroku one-off dyno that exited - heroku

Suppose I started a one-off process using this command:
heroku run:detached "node do-some-stuff.js" --app my-app
The output of the command is this:
/usr/local/heroku/lib/heroku/jsplugin.rb:108: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
Running `node do-some-stuff.js` detached... up, run.3728
Use `heroku logs -p run.3728 -a my-app` to view the output.
I can heroku logs -p run.3728 -a my-app while the process is being run, however, when process has exited it outputs nothing. How do i view the logs for process that has finished?

If you using a logging plugin, just search for run.3728. For a short period of time, the logs will also still be in the heroku logs if you do heroku logs | grep run.3728

Related

Run Heroku Bash Command 7/24

I have to open the Heroku bash and type "node main.js" to run my app. But when I close my browser the script stops. How can I run the script 24/7?
You seem to be new to heroku, this should help
In your package.json file mention a start script:
"scripts": {
"start": "node main.js",
...
}
(If you don't have a package.json make sure to run npm init -y and commit this file)
And to scale(run) your app:
heroku ps:scale web=1
Your heroku app should automatically be detected as a node application and it would run the start script upon starting
To see the logs and debug, do:
heroku logs --tail --num=10
and then try visiting your app with the terminal open to see live logs
If you have further problems, make sure to include your logs without any credentials possibly leaked

Heroku logs are flooded with the log-runtime-metrics

The set of logs below is appearing every 20 seconds on my heroku app log.
heroku[web.1]: source=web.1 dyno=heroku.... sample#load_avg_1m=0.00
heroku[web.1]: source=web.1 dyno=heroku.... sample#memory_total=18.06MB sample#memory_rss=17.37MB sample#memory_cache=0.69MB sample#memory_swap=0.00MB sample#memory_pgpgin=7511pages sample#memory_pgpgout=2888pages sample#memory_quota=512.00MB
I've found out these are Runtime metrics logs (https://devcenter.heroku.com/articles/log-runtime-metrics), not error logs.
I've tried these commands to disable this function but it didn't make any sense.
$ heroku labs:disable log-runtime-metrics
$ heroku restart
$ git commit --allow-empty -m "Force Heroku build."
$ git push heroku master
I also checked my heroku labs feature conditions by the command below.
$ heroku labs
It says log-runtime-metrics is not activated.
I completely don't have any idea for the cause of this behavior.

How to handle log drains in one-off dynos?

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.

exec sidekiq log on heroku

I want to exec the sidekiq log file on my heroku environment but I cannot find anything in the documentation nor google helps me here. I am sure it has to be sth like exec sidekiq -L log/sidekiq.logbut that command fails on heroku.
How can I access my sidekiq log file on a heroku environment?
The easiest way would be
heroku logs --tail --app app_name --dyno worker
This will only show worker logs.
I grabbed the worker logger on heroku
heroku logs -t -a eventbaxx-production | grep worker.1
so I could see sidekiq activity.

How to see untrimmed logs on Heroku Local

I'm running a NodeJS app on heroku local, however all my console.log statements and error messages get trimmed.
For example:
forego | starting web.1 on port 5000
web.1 | module.js:339
I don't see the full error logs. How to avoid this trimming of error messages?
heroku local will run whatever processes you tell it to in the Procfile. If you'd like to stream your development log, simply add something like log: tail -f log/development.log to your Procfile. You'll also want to make sure that you create a second Procfile (I use Procfile.dev) for this. Replace the log file path with wherever your desired log file is located.
Cheers!
Did you try?
$ heroku help local
Source: https://devcenter.heroku.com/articles/heroku-local
Is this deployed already? If so:
On terminal/bash:
$ heroku logs
On your heroku account:
1) Go to you account and then apps and then the log for that app

Resources