简体   繁体   English

如何使用nodejs包含自定义记录器?

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

相关问题 如何使用 `require` 而不是 `include` 包含我的自定义组件 - How do I include my custom Component using `require` instead of `include` 我的私有组件应包含多少安全逻辑? - How much safety logic should I include in my private components? 我应该如何包含和引用我的JavaScript文件 - How should I include and reference my JavaScript files 我应该如何为我的AngularJS项目添加代码文件? - How should I include the code files for my AngularJS project? 我是否应该在我的前端网站代码(通过 Firebase 托管)中包含我的 NodeJS/Express 服务器代码(托管在 Heroku 上)? - Should I include my NodeJS/Express server code (hosted on Heroku) with my front-end website code (hosted through Firebase)? 在Orchard cms我想要包含某些.js文件,我应该把它们放在哪里以及如何将它包含在我的项目中? - In Orchard cms I want to include certain .js files, where should i put them and how should i include it in my project? 如何在查询中包含自定义 SELECT - How can I include custom SELECTs in my queries 我可以在我的网站中包含这个 JavaScript/NodeJS/express 应用程序吗? - Can I include this JavaScript/NodeJS/express app in my website? 我应该如何在 AllValidate 函数中包含这些函数? - How should I include these functions in AllValidate function? NodeJS:如何在不使用require的情况下包含一些javascript代码段? - NodeJS: How can I include some javascript code snippet without using require?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM