[英]How should I include my custom logger using nodejs?
I wish to include my custom log in loggings,I am using pino module for loggings, Here is the log example This is the response every time when I am hitting my API 我希望在日志记录中包含我的自定义日志,我正在使用pino模块进行日志记录,这是日志示例这是每次我点击API时的响应
"1493118596934" "TRACE" "services-mc" "victoria-lap" "sr" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "" "GET" "/user/v1/favoritepets/?userId=123" "request received"
"1493118598480" "TRACE" "services-mc" "victoria-lap" "" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "" "GET" "/user/v1/favoritepets/?userId=123" ""
"1493118598490" "TRACE" "services-mc" "victoria-lap" "" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "" "GET" "/user/v1/favoritepets/?userId=123" ""
"1493118598494" "TRACE" "services-mc" "victoria-lap" "ss" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "200" "GET" "/users/v1/favoritepets/?userId=123" "response sent"
Here I have to include my custom log like this 在这里,我必须像这样包含我的自定义日志
"1493118596934" "TRACE" "services-mc" "victoria-lap" "sr" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "" "GET" "/user/v1/favoritepets/?userId=123" "request received"
*"pet_hit_journal" "15829507" "2017-03-10" "741184567" "" "web"*
"1493118598480" "TRACE" "services-mc" "victoria-lap" "" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "" "GET" "/user/v1/favoritepets/?userId=123" ""
"1493118598490" "TRACE" "services-mc" "victoria-lap" "" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "" "GET" "/user/v1/favoritepets/?userId=123" ""
"1493118598494" "TRACE" "services-mc" "victoria-lap" "ss" "" "" "094ce63c-e067-4c4e-a441-92c247f0ed43" "200" "GET" "/users/v1/favoritepets/?userId=123" "**response sent**"
Note: The custom log messages for knowing that the data is fetched from the database when I am using the particular controller. 注意:当我使用特定控制器时,用于了解从数据库中获取数据的定制日志消息。 Should it be possible?
应该有可能吗? any idea, please...
任何想法,请...
Logging in Hapi can be done through the server.log
and request.log
functions. 可以通过
server.log
和request.log
函数完成Hapi登录。
It's possible to intercept these manually and add any extra information you need using server.on('log', ...)
and server.on('request', ...)
before continuing to log your message. 在继续记录消息之前
server.on('request', ...)
可以使用server.on('log', ...)
和server.on('request', ...)
手动拦截这些消息并添加您需要的任何其他信息。 To keep your code organized, you can also wrap these in a custom plugin . 为了使代码井井有条,您还可以将其包装在自定义插件中 。 In one of these is likely where you would include your custom logger.
在其中一种可能中,您将包括自定义记录器。
You should take a look at the Logging Tutorial as it explains the parameters for the above functions. 您应该看一下Logging Tutorial,因为它解释了上述功能的参数。
Good is an official plugin to monitor and report on hapi server events. Good是一个用于监视和报告hapi服务器事件的官方插件。 Also have a look at this.
也看看这个。 Good-console will help you output those events to the console.
良好的控制台将帮助您将这些事件输出到控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.