[英]Using nodejs's Forever to output console.logs to screen
I just discovered that my nodejs app keeps crashing, so I've used forever app.js
to start my app and have it automatically restarted when it crashes.我刚刚发现我的 nodejs 应用程序不断崩溃,所以我一直使用
forever app.js
来启动我的应用程序,并在它崩溃时自动重新启动。
Problem: Now my app outputs alot of useful information as it runs via console.log
and util.log
.问题:现在我的应用程序输出了很多有用的信息,因为它通过
console.log
和util.log
运行。 I used to use screen
to run the node app, but now that I'm using forever to run the nodejs app, I can no longer see all the outputs.我曾经使用
screen
来运行 node 应用程序,但是现在我永远使用它来运行 nodejs 应用程序,我再也看不到所有的输出了。
Is there any way to see all the output from the nodejs app in realtime?有没有办法实时查看 nodejs 应用程序的所有输出?
You can watch a logfile live by using this shell-command.您可以使用此 shell 命令实时查看日志文件。
tail -f /path/to/logfile
Not sure if this is what you needed.不确定这是否是您所需要的。
Directly with forever command :直接使用永久命令:
forever logs app.js -f
It shows in realtime output of your application and forever logs (shows detected changes & restart messages).它显示您的应用程序的实时输出和永久日志(显示检测到的更改和重新启动消息)。
Simplest way to go is最简单的方法是
Run :跑步 :
forever logs // will give you list of log files
forever logs 0 -f // then just provide the index of log
If you pass the --help
flag to Forever you'll see this example:如果您将
--help
标志传递给 Forever,您将看到以下示例:
forever -o out.log -e err.log my-script.js
-o
and -e
define the stdout and stderr log files. -o
和-e
定义 stdout 和 stderr 日志文件。
-o OUTFILE Logs stdout from child script to OUTFILE
-e ERRFILE Logs stderr from child script to ERRFILE
Forever seems a little overkill for development. Forever 对于开发来说似乎有点矫枉过正。 Give Supervisor a shot and see if you like it better:
给主管一个机会,看看你是否更喜欢它:
npm install -g supervisor
supervisor app.js
I am running nodejs on AWS EC2 instance and this worked for me.我在 AWS EC2 实例上运行 nodejs,这对我有用。 Note: logs are accessible if you are root owner.
注意:如果您是 root 所有者,则可以访问日志。 So first use sudo su then
所以首先使用sudo su然后
forever -a -o out.log -e err.log yourServerApp.js
It will tail console log (in case you track event messages from log) and error log.它将跟踪控制台日志(以防您从日志跟踪事件消息)和错误日志。 I hope it helps someone.
我希望它可以帮助某人。
linux : tail -f /path/to/logfile.log
windows : enter PowerShell -> Get-Content /path/to/logfile.log -Wait -Tail 1000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.