Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log is not displayed in heroku logs

Tags:

heroku

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.

like image 427
eugenekr Avatar asked Oct 30 '17 14:10

eugenekr


1 Answers

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

like image 62
Arunabh Das Avatar answered Sep 17 '22 11:09

Arunabh Das