node.js 如何在heroku中显示node.js中的所有console.log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30963399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to show all console.log from node.js in heroku?
提问by Pindakaas
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: "[email protected]",
pass: "mypw"
}
});
smtpTransport.sendMail({
from: "Dikkebil", // sender address
to: "[email protected]", // 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);
}
});
回答by michelem
From the heroku doc:
来自 heroku 文档:
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.
因此,您可能需要请求更多带有-n选项的行。
As per comment received, you can also stream the current log with:
根据收到的评论,您还可以使用以下内容流式传输当前日志:
$ heroku logs --tail
Please look at the doc
请看文档
回答by Sebastian SALAMANCA
I always use heroku logs -t --app your-app-nameIt keeps the herokuconsole open .
我总是使用heroku logs -t --app your-app-name它保持heroku控制台打开。
回答by ILoveReactAndNode
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。
回答by Risto Novik
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。

