Angular version: 1.5.11
angular-logger
angular-logger是一个方便的实现前端日志输出的套件,并且可以在日志当中打印时间,日志来自的模块等等信息。
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端推荐采用的日志框架。可以配置文件输出,标准输出等等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里面也会有以下内容。