如何在heroku中显示来自node.js的所有console.log? [英] how to show all console.log from node.js in heroku?

查看:131
本文介绍了如何在heroku中显示来自node.js的所有console.log?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  heroku日志

显示了一些日志记录,但看起来并不是完整的日志。是否有一个node.js包从部署的应用程序发送电子邮件?邮件代码:

  console.log('尝试发送电子邮件等待'); 
var nodemailer = require(nodemailer);
var smtpTransport = nodemailer.createTransport({
服务:Gmail,
auth:{
user:myemail@gmail.com,
pass: mypw
}
});

smtpTransport.sendMail({
来自:Dikkebil,//发件人地址
至:myemail@gmail.com,//逗号分隔的接收者列表
主题:Error body,//主题行
文本:'错误正文:'+ error.body +'\\\
'+'错误类型:'+ error.type +'\\\
'+ 'error statuscode:'+ error.statusCode +'\\\
'+'error args:'+ error.arguments [0]
},function(error,response){
if(error){
console.log(error);
} else {
console.log(Message sent:+ response.message);
}
});


解决方案

从heroku文档:


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

blockquote>

  $ heroku日志-n 200 

因此,您可能需要使用 -n 选项来请求更多行。



根据收到的评论,你也可以用当前的日志流:

  $ heroku logs --tail 

看看doc


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

解决方案

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

这篇关于如何在heroku中显示来自node.js的所有console.log?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆