javascript 使用 nodejs 的 Forever 将 console.logs 输出到屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10368973/
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
Using nodejs's Forever to output console.logs to screen
提问by Nyxynyx
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
. 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.
问题:现在我的应用程序在通过console.log
和运行时输出了很多有用的信息util.log
。我曾经用来screen
运行 node 应用程序,但是现在我永远使用它来运行 nodejs 应用程序,我再也看不到所有的输出了。
Is there any way to see all the output from the nodejs app in realtime?
有没有办法实时查看 nodejs 应用程序的所有输出?
回答by arnaud del.
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).
它显示您的应用程序的实时输出和永久日志(显示检测到的更改和重新启动消息)。
回答by Zombaya
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.
不确定这是否是您所需要的。
回答by Vivek Doshi
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
回答by jwerre
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. Give Supervisora shot and see if you like it better:
Forever 对于开发来说似乎有点矫枉过正。给主管一个机会,看看你是否更喜欢它:
npm install -g supervisor
supervisor app.js
回答by StefaDesign
I am running nodejs on AWS EC2 instance and this worked for me. Note: logs are accessible if you are root owner. So first use sudo suthen
我在 AWS EC2 实例上运行 nodejs,这对我有用。注意:如果您是 root 所有者,则可以访问日志。所以首先使用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.
它将跟踪控制台日志(以防您从日志跟踪事件消息)和错误日志。我希望它可以帮助某人。