think-logger3
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "think-logger3", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "logger for ThinkJS 3.x", | ||
@@ -32,4 +32,4 @@ "main": "./src", | ||
"ava": "^0.18.2", | ||
"babel-eslint": "^7.1.1", | ||
"eslint": "^3.16.1", | ||
"eslint": "^4.2.0", | ||
"eslint-config-think": "^1.0.1", | ||
"nyc": "^10.1.2", | ||
@@ -36,0 +36,0 @@ "sandboxed-module": "^2.0.3" |
const log4js = require('log4js'); | ||
const cluster = require('cluster'); | ||
const _logger = Symbol('_logger'); | ||
module.exports = class { | ||
constructor() { | ||
this._logger = {}; | ||
this[_logger] = {}; | ||
} | ||
debug(...args) { | ||
return this._logger.debug(...args); | ||
return this[_logger].debug(...args); | ||
} | ||
info(...args) { | ||
return this._logger.info(...args); | ||
return this[_logger].info(...args); | ||
} | ||
warn(...args) { | ||
return this._logger.warn(...args); | ||
return this[_logger].warn(...args); | ||
} | ||
error(...args) { | ||
return this._logger.error(...args); | ||
return this[_logger].error(...args); | ||
} | ||
/** | ||
@@ -33,7 +35,7 @@ * log4js configure | ||
/** | ||
* log4js getLogger | ||
* log4js setLogger | ||
*/ | ||
getLogger(config, category) { | ||
setLogger(config, category) { | ||
this.configure(config); | ||
return log4js.getLogger(category); | ||
this[_logger] = log4js.getLogger(category); | ||
} | ||
@@ -45,8 +47,8 @@ | ||
isCluster(config, clusterMode) { | ||
let lConfig = Object.assign({}, config); | ||
let appenders = config.appenders; | ||
const lConfig = Object.assign({}, config); | ||
const appenders = config.appenders; | ||
delete lConfig.appenders; | ||
if( cluster.isWorker ) { | ||
//worker log4js config | ||
if (cluster.isWorker) { | ||
// worker log4js config | ||
return Object.assign({ | ||
@@ -59,10 +61,10 @@ appenders: [ | ||
//Master process | ||
if(typeof(clusterMode) === 'undefined') { | ||
// Master process | ||
if (typeof (clusterMode) === 'undefined') { | ||
clusterMode = Object.keys(cluster.workers).length; | ||
} | ||
if(!clusterMode) { | ||
if (!clusterMode) { | ||
return config; | ||
} | ||
return Object.assign({ | ||
@@ -77,2 +79,2 @@ appenders: [ | ||
} | ||
}; | ||
}; |
@@ -7,6 +7,6 @@ const Base = require('./base'); | ||
let lConfig = Object.assign({}, config); | ||
const lConfig = Object.assign({}, config); | ||
let {level, layout} = lConfig; | ||
level = level ? level.toUpperCase() : 'ALL'; | ||
layout = layout ? layout : {type: 'pattern', pattern: '%[[%d] [%p]%] - %m'}; | ||
layout = layout || {type: 'pattern', pattern: '%[[%d] [%p]%] - %m'}; | ||
@@ -19,4 +19,4 @@ config = Object.assign({ | ||
this._logger = this.getLogger(config); | ||
this.setLogger(config); | ||
} | ||
}; | ||
}; |
@@ -7,7 +7,8 @@ const Base = require('./base'); | ||
let lConfig = Object.assign({}, config); | ||
const lConfig = Object.assign({}, config); | ||
// eslint-disable-next-line prefer-const | ||
let {level, filename, pattern, alwaysIncludePattern, absolute, layouts} = lConfig; | ||
level = level ? level.toUpperCase() : 'ALL'; | ||
//combine config for date file appender, common config for log4js | ||
// combine config for date file appender, common config for log4js | ||
config = Object.assign({ | ||
@@ -19,7 +20,7 @@ appenders: [ | ||
//check cluster mode | ||
// check cluster mode | ||
config = this.isCluster(config, clusterMode); | ||
this._logger = this.getLogger(config); | ||
this.setLogger(config); | ||
} | ||
}; |
@@ -7,7 +7,8 @@ const Base = require('./base'); | ||
let lConfig = Object.assign({}, config); | ||
const lConfig = Object.assign({}, config); | ||
// eslint-disable-next-line prefer-const | ||
let {level, filename, maxLogSize, backups, absolute, layouts} = config; | ||
level = level ? level.toUpperCase() : 'ALL'; | ||
//combine config for file appender, common config for log4js | ||
// combine config for file appender, common config for log4js | ||
config = Object.assign({ | ||
@@ -18,7 +19,7 @@ appenders: [ | ||
}, lConfig); | ||
//check cluster mode | ||
// check cluster mode | ||
config = this.isCluster(config, clusterMode); | ||
this._logger = this.getLogger(config); | ||
this.setLogger(config); | ||
} | ||
}; | ||
}; |
@@ -7,4 +7,4 @@ const Base = require('./base'); | ||
let lConfig = Object.assign({}, lConfig); | ||
let {host, hostname, port, facility} = lConfig; | ||
const lConfig = Object.assign({}, config); | ||
const {host, hostname, port, facility} = lConfig; | ||
config = Object.assign({ | ||
@@ -14,4 +14,4 @@ appenders: [{type: 'gelf', host, hostname, port, facility}] | ||
this._logger = this.getLogger(config); | ||
this.setLogger(config); | ||
} | ||
}; | ||
}; |
@@ -8,6 +8,6 @@ const assert = require('assert'); | ||
constructor(config, clusterMode) { | ||
let handle = config.handle || ConsoleAdapter; | ||
const Handle = config.handle || ConsoleAdapter; | ||
delete config.handle; | ||
this._logger = new handle(config, clusterMode); | ||
this._logger = new Handle(config, clusterMode); | ||
['debug', 'info', 'warn', 'error'].forEach(level => { | ||
@@ -14,0 +14,0 @@ assert(this._logger[level], `adapter function ${level} not exist!`); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146214
683