Angular version: 1.5.11
angular-logger
angular-logger是一個(gè)方便的實(shí)現(xiàn)前端日志輸出的套件觉既,并且可以在日志當(dāng)中打印時(shí)間糯耍,日志來自的模塊等等信息库车。
bower install angular-logger --save
'use strict';
angular.module('basic', ['angular-logger']).config(function (logEnhancerProvider) {
logEnhancerProvider.prefixPattern = '%s - %s: ';
}).run(['$log', function ($log) {
$log.getInstance('app').info('Hello World');
$log.getInstance('app').warn('Hello World');
$log.getInstance('app').error('Hello World');
$log.getInstance('app').debug('Hello World');
$log.getInstance('app').log('Hello World');
}]);
Chrome輸出如下:
log4js-node
log4js-node是我們Node Server端推薦采用的日志框架渣淳「髂可以配置文件輸出茄猫,標(biāo)準(zhǔn)輸出等等Appenders.
npm install log4js --save-dev
import log4js from 'log4js';
log4js.configure({
appenders: {
out: { type: 'stdout' },
app: { type: 'file', filename: 'application.log' }
},
categories: {
default: { appenders: [ 'out', 'app' ], level: 'debug' }
}
});
const logger = log4js.getLogger('app');
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.');
在application log里面也會(huì)有以下內(nèi)容誊抛。