NodeJS日志框架:Bragi

jopen 10年前發布 | 32K 次閱讀 Bragi 日志處理

Bragi是一個獨立,先進的 NodeJS日志框架。可以為輸入的日志信息著色,定義日志級別和服務器報告功能。Bragi能夠讓你在代碼中編寫日志信息,并指定哪些日志輸出到控制臺中。

安裝和用法

$ npm install bragi

Then, include it in your code:

var logger = require('bragi'); 

Next, log something:

logger.log('groupname', 'Hello world'); 

Calls to log take in two required parameters: groupName and message. Any additional parameters (such as object info) will be included in the log message also. For instance:

logger.log('groupname', 'Here is some user info', { name: 'Ironman', weaknesses: null }); 

One of the benefits Bragi provides is the ability to supply arbitrary group names and namespace for groups (separated by a colon). For instance:

logger.log('userController:fetchInfo', 'fetching user information...'); 

Because the groupname is a string, you can dynamically create it:

logger.log('userController:fetchInfo:ironman', 'fetching user information...'); 

With group names, we're able to filter messages by groups and their namespaces, or by a regular expression (e.g., we have the ability to show ALL logs for the ironman user)

687474703a2f2f73332e616d617a6f6e6177732e636f6d2f76617369722d6173736574732f62726167692f62726167692d6c6f672d7374696c6c2d736d616c6c2e706e67.png

項目主頁:http://www.baiduhome.net/lib/view/home/1408520703647

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!