[英]Configuration parameters in pm2 to display colors in console
I use pm2 to keep my node.js app alive, I am starting my app with a configuration file that looks like this:我使用 pm2 来保持我的 node.js 应用程序处于活动状态,我使用如下所示的配置文件启动我的应用程序:
{
"name" : "myApp",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"ignoreWatch" : ["node_modules","public"],
"watch" : true,
}
Additionally I am using the package colors to identify different types of messages but all the logs lose their color when I run the command此外,我使用包颜色来识别不同类型的消息,但是当我运行命令时所有日志都失去了它们的颜色
pm2 logs
My question is: what can I add to my configuration file to be able to see the colors in console?我的问题是:我可以在配置文件中添加什么才能在控制台中看到颜色?
When I did use a other logger modules, (like a colors , tracer )当我确实使用其他记录器模块时,(如颜色、示踪剂)
(In my case, var logger = require('tracer').colorConsole();
as logger ) (在我的例子中, var logger = require('tracer').colorConsole();
作为 logger )
{
"args": [ "--color" ]
}
this "args": "--color"
keeps my logger's log color.这个"args": "--color"
保持我记录器的日志颜色。
Insert that code in your pm2 script,将该代码插入您的 pm2 脚本中,
then you can see your color log by that command: pm2 logs "id" --raw
(id is a pm2 id)然后您可以通过该命令查看您的颜色日志: pm2 logs "id" --raw
(id is a pm2 logs "id" --raw
id)
{
"name" : "myApp",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"ignoreWatch" : ["node_modules","public"],
"watch" : true,
"args": [
"--color"
]
}
The process is needed to pm2 stop
, pm2 delete
and new pm2 start using script. pm2 stop
, pm2 delete
和 new pm2 start 需要这个过程使用脚本。
I found I also needed to add this option for debug to my pm2 process.json
file我发现我还需要将此选项添加到我的pm2 process.json
文件中进行调试
"env": { "DEBUG_COLORS": true }
then can view colored debug logs with both pm2 logs
and pm2 logs --raw
然后可以查看带有pm2 logs --raw
pm2 logs
和pm2 logs --raw
彩色调试日志
Try using the --raw
switch.尝试使用--raw
开关。 Like this —像这样 -
pm2 logs --raw
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.