eugenekr
eugenekr

Reputation: 6602

console.log is not displayed in heroku logs

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.

Upvotes: 8

Views: 3015

Answers (2)

Alongkorn
Alongkorn

Reputation: 4207

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

Upvotes: 1

Arunabh Das
Arunabh Das

Reputation: 14382

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

Upvotes: 2

Related Questions