Log4js 2.9.0 日記治理插件

Node端的日記插件Log4js,今後版本更新了繼承跟進

裝置&&版本

npm install log4js
或許
yarn add log4js
    "express": "4.16.2",
    "log4js": "2.9.0",

最簡樸的寫法

var log4js = require('log4js');
var logger = log4js.getLogger();
logger.level = 'debug';
logger.debug("Some debug messages");

輕微詳細一些

const log4js = require('log4js');
log4js.configure({
  appenders: { cheese: { type: 'file', filename: 'cheese.log' } },
  categories: { default: { appenders: ['cheese'], level: 'error' } }
});

const logger = log4js.getLogger('cheese');
logger.trace('Entering cheese testing');
logger.debug('Got cheese.');
logger.info('Cheese is Gouda.');
logger.warn('Cheese is quite smelly.');
logger.error('Cheese is too ripe!');
logger.fatal('Cheese was breeding ground for listeria.');

輸出效果

[2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
[2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.

參考文獻

https://github.com/log4js-nod…

    原文作者:雲中的貓
    原文地址: https://segmentfault.com/a/1190000015334798
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞