NodeJS日志框架:Bragi
jopen
10年前
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)