8

I have the program heroku_test.ts console.log('test') I can run it with the following command: heroku run ts-node heroku_test.ts In the same console window I see it output 'test' But when I look at heroku logs, there is no 'test' there, it just says "Starting process with command ts-node heroku_test.ts"

Why heroku logs do not contain console.log output?

EDIT: the question is different from how to show all console.log from node.js in heroku? because I can see all the logs except any console.log output.

eugenekr
  • 6,260
  • 3
  • 21
  • 26
  • Possible duplicate of [how to show all console.log from node.js in heroku?](https://stackoverflow.com/questions/30963399/how-to-show-all-console-log-from-node-js-in-heroku) – Koby Douek Oct 30 '17 at 14:13

2 Answers2

2

First install winston :

https://github.com/winstonjs/winston

as follows :

npm install winston --save

Then change your heroku_test.js to the following :

const winston = require('winston')

winston.log('info', '-------Hello log files!------------', {  
  someKey: 'some-value'
})

Then run

heroku run node heroku_test.js

Then check the logs :

heroku logs --tail

and you should see the above in the heroku logs

Arunabh Das
  • 13,212
  • 21
  • 86
  • 109
1

you can try some opensource libs, e.g., https://www.npmjs.com/package/heroku-logger

Alongkorn
  • 3,968
  • 1
  • 24
  • 41