how to show all console.log from node.js in heroku?

假装没事ソ 提交于 2019-12-31 11:02:12

问题


I have deployed a node.js application to node.js but not able to see the complete console.log statements from my app. I am using:

heroku logs

Some of the logging is shown but looks like it is not the complete logs. Is there a node.js package to send emails from the deployed app? Email works fine from my localmachine btw.

Email code:

console.log('try to send email hold on');
    var nodemailer = require("nodemailer");
    var smtpTransport = nodemailer.createTransport({
        service: "Gmail",
        auth: {
            user: "myemail@gmail.com",
            pass: "mypw"
        }
    });

    smtpTransport.sendMail({
        from: "Dikkebil", // sender address
        to: "myemail@gmail.com", // comma separated list of receivers
        subject: "Error body", // Subject line
        text: 'Error body: ' +error.body+ '\n'+ 'error type:' + error.type +'\n' +'error statuscode:' +error.statusCode +'\n'  + 'error args:' + error.arguments[0]
    }, function(error, response){
        if(error){
            console.log(error);
        }else{
            console.log("Message sent: " + response.message);
        }
    });

回答1:


From the heroku doc:

The logs command retrieves 100 log lines by default. You can specify the number of log lines to retrieve (up to a maximum of 1,500 lines) by using the --num (or -n) option.

$ heroku logs -n 200

So probably you need to request more lines with -noption.

As per comment received, you can also stream the current log with:

$ heroku logs --tail

Please look at the doc




回答2:


I always use heroku logs -t --app your-app-name It keeps the heroku console open .




回答3:


The problems seems to be that the Heroku holds maximum 1500 lines of logs. To persists and have an ability to see more history you have to add some syslog drain to catch the logs or use some addon for that.

There are also "free" addons for storing logs like Logentries and Papertrail https://addons.heroku.com/#logging.




回答4:


I use:

heroku logs -n 1000 --tail

that 1000 is the number of lines you want to see and can be up to 1500.



来源:https://stackoverflow.com/questions/30963399/how-to-show-all-console-log-from-node-js-in-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!