如何在heroku中显示来自node.js的所有console.log?

时间:2022-09-26 16:55:41

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:

我已经将node.js应用程序部署到node.js,但无法从我的应用程序中看到完整的console.log语句。我在用:

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.

显示了一些日志记录,但看起来它不是完整的日志。是否有node.js包来从已部署的应用程序发送电子邮件?电子邮件在我的本地机器上运行正常。

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);
        }
    });

4 个解决方案

#1


29  

From the heroku doc:

来自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.

logs命令默认检索100个日志行。您可以使用--num(或-n)选项指定要检索的日志行数(最多1,500行)。

$ heroku logs -n 200

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

因此,您可能需要使用-noption请求更多行。

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

根据收到的评论,您还可以使用以下内容流式传输当前日志:

$ heroku logs --tail

Please look at the doc

请看文档

#2


9  

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

我总是使用heroku logs -t --app你的应用程序名称它保持heroku控制台打开。

#3


2  

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.

问题似乎是Heroku拥有最多1500行日志。要坚持并且有能力查看更多历史记录,您必须添加一些syslog消耗来捕获日志或使用一些插件。

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

还有用于存储日志的“免费”插件,如Logentries和Papertrail https://addons.heroku.com/#logging。

#4


0  

I use:

我用:

heroku logs -n 1000 --tail

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

1000是您想要查看的行数,最多可达1500。

#1


29  

From the heroku doc:

来自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.

logs命令默认检索100个日志行。您可以使用--num(或-n)选项指定要检索的日志行数(最多1,500行)。

$ heroku logs -n 200

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

因此,您可能需要使用-noption请求更多行。

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

根据收到的评论,您还可以使用以下内容流式传输当前日志:

$ heroku logs --tail

Please look at the doc

请看文档

#2


9  

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

我总是使用heroku logs -t --app你的应用程序名称它保持heroku控制台打开。

#3


2  

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.

问题似乎是Heroku拥有最多1500行日志。要坚持并且有能力查看更多历史记录,您必须添加一些syslog消耗来捕获日志或使用一些插件。

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

还有用于存储日志的“免费”插件,如Logentries和Papertrail https://addons.heroku.com/#logging。

#4


0  

I use:

我用:

heroku logs -n 1000 --tail

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

1000是您想要查看的行数,最多可达1500。