简体   繁体   English

使用 nodejs 的 Forever 将 console.logs 输出到屏幕

[英]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.logutil.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.

相关问题 如何在nodemon中隐藏黄色的console.logs - How to hide the yellow console.logs in nodemon Windows Vista Internet Explorer 9 console.logs - Windows vista Internet Explorer 9 console.logs VSCODE 未显示 javascript 功能 console.logs - VSCODE not showing javascript fuction console.logs 在 Google Chrome 中看不到 console.logs - Cannot see console.logs in Google Chrome 为什么Generator中的console.logs会以这种顺序出现? - Why console.logs in generator appears in such order? 如何在开发中自动删除 console.logs()? - How to automatically remove console.logs() in development? 在 render() 中反应组件 console.logs 2 次 - React component console.logs 2 times in render() 是否有太多console.logs影响单页应用程序/选项卡的内存和性能? - Do too many console.logs affect Single Page application's/tab's memory and performance? 可以通过console.logs绕过Heroku的免费计划“在30分钟不活动后睡觉”? - Possible to bypass Heroku's free plan's “Sleeps after 30 mins of inactivity” with console.logs? 为什么 console.logs 与中呈现的 output 不匹配<text>在这个基本的 React Native Expo 项目中的表达式</text> - Why does console.logs does not matched the output rendered in <Text> expression in this basic React Native Expo Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM