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

时间:2012-04-29 01:26:51

标签: javascript jquery node.js

我刚发现我的nodejs应用程序一直崩溃,所以我使用forever app.js来启动我的应用程序,并在崩溃时自动重启。

问题:现在,我的应用会在通过console.logutil.log运行时输出大量有用信息。我曾经使用screen运行节点应用程序,但现在我正在使用永远运行nodejs应用程序,我再也看不到所有输出了。

有没有办法实时查看nodejs应用程序的所有输出?

6 个答案:

答案 0 :(得分:26)

直接与永远的命令:

forever logs app.js -f

它显示应用程序的实时输出并永久记录(显示检测到的更改和重新启动消息)。

答案 1 :(得分:24)

您可以使用此shell命令来实时查看日志文件。

 tail -f /path/to/logfile

不确定这是否是您所需要的。

答案 2 :(得分:4)

最简单的方法是

运行:

forever logs // will give you list of log files
forever logs 0 -f // then just provide the index of log

答案 3 :(得分:3)

如果您将--help标记传递给Forever,您会看到以下示例:

forever -o out.log -e err.log my-script.js

-o-e定义stdout和stderr日志文件。

-o  OUTFILE      Logs stdout from child script to OUTFILE
-e  ERRFILE      Logs stderr from child script to ERRFILE

永远似乎对发展有点过分。给Supervisor一个镜头,看看你是否更喜欢它:

npm install -g supervisor
supervisor app.js

答案 4 :(得分:0)

我正在AWS EC2实例上运行nodejs,这对我有用。 注意:如果您是root所有者,则可以访问日志。因此,请先使用 sudo su 然后

forever -a -o out.log -e err.log yourServerApp.js

它将跟踪控制台日志(以防您从日志中跟踪事件消息)和错误日志。希望对您有所帮助。

答案 5 :(得分:0)

#include <iostream>
#include "circle.h" //include the header file for circle
#include "square.h"  //include the header file for square

using namespace std;

int main()
{
    int radius.length;
    Circle circle; //Displaying a circle using the default value of the radius
    circle Display();
    Circle circ; //This is the circle with the data entered for the radius

    cout << "Enter a radius value for the circle: " endl;  //Prompt the user to input the radius
    cin >> Radius;  //read the input

    circ setRadius (radius);
    circ Display();

    Square square;  //Displaying a square using the default value
    square Display();
    Square sqre; //This is the square with the data entered for the length

    cout << "Enter the length of one side of the square: " endl;  //Prompt the user to input the length
    cin >> length; //read the input

    sqre.setLength(length);  //from the base class
    sqre Display();


    return 0;
}