graceful-process
Advanced tools
Comparing version 1.0.0 to 1.1.0
1.1.0 / 2018-01-17 | ||
================== | ||
**features** | ||
* [[`180028b`](http://github.com/node-modules/graceful-process/commit/180028be79b2d55ac3142e24b272f7552f3bbb25)] - feat: add logLevel to control print log level (#3) (fengmk2 <<fengmk2@gmail.com>>) | ||
**others** | ||
* [[`7edd157`](http://github.com/node-modules/graceful-process/commit/7edd1578ad15264b1e7e8395ffbeb174865694e6)] - test: add more assert on tests (#2) (fengmk2 <<fengmk2@gmail.com>>) | ||
* [[`b838376`](http://github.com/node-modules/graceful-process/commit/b838376b42a239c9d8a61a4e3ce0b167d327119b)] - deps: use nyc version of egg-bin (#1) (fengmk2 <<fengmk2@gmail.com>>) | ||
1.0.0 / 2017-06-12 | ||
@@ -3,0 +13,0 @@ ================== |
24
index.js
@@ -8,5 +8,22 @@ 'use strict'; | ||
const logger = options.logger || console; | ||
let logLevel = (options.logLevel || 'info').toLowerCase(); | ||
if (logger !== console) { | ||
// don't handle custom logger level | ||
logLevel = 'info'; | ||
} | ||
const printLogLevels = { | ||
info: true, | ||
warn: true, | ||
error: true, | ||
}; | ||
if (logLevel === 'warn') { | ||
printLogLevels.info = false; | ||
} else if (logLevel === 'error') { | ||
printLogLevels.info = false; | ||
printLogLevels.warn = false; | ||
} | ||
const label = options.label || `graceful-process#${process.pid}`; | ||
if (process[init]) { | ||
logger.warn('[%s] graceful-process init already', label); | ||
printLogLevels.warn && logger.warn('[%s] graceful-process init already', label); | ||
return; | ||
@@ -19,3 +36,3 @@ } | ||
process.once('SIGTERM', () => { | ||
logger.info('[%s] receive signal SIGTERM, exiting with code:0', label); | ||
printLogLevels.info && logger.info('[%s] receive signal SIGTERM, exiting with code:0', label); | ||
process.exit(0); | ||
@@ -26,3 +43,3 @@ }); | ||
const level = code === 0 ? 'info' : 'error'; | ||
logger[level]('[%s] exit with code:%s', label, code); | ||
printLogLevels[level] && logger[level]('[%s] exit with code:%s', label, code); | ||
}); | ||
@@ -36,3 +53,2 @@ | ||
if (cluster.worker.exitedAfterDisconnect) return; | ||
logger.error('[%s] receive disconnect event in cluster fork mode, exitedAfterDisconnect:false', label); | ||
@@ -39,0 +55,0 @@ }); |
{ | ||
"name": "graceful-process", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "graceful exit process even parent exit on SIGKILL.", | ||
@@ -24,11 +24,12 @@ "files": [ | ||
"author": "fengmk2", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"autod": "^2.8.0", | ||
"coffee": "^3.3.2", | ||
"coffee": "^4.0.1", | ||
"cross-env": "^5.0.1", | ||
"egg-bin": "^3.4.2", | ||
"egg-ci": "^1.7.0", | ||
"eslint": "^3.19.0", | ||
"eslint-config-egg": "^4.2.0", | ||
"egg-bin": "^4.0.4", | ||
"egg-ci": "^1.8.0", | ||
"eslint": "^4.0.0", | ||
"eslint-config-egg": "^4.2.1", | ||
"mz-modules": "^1.0.0", | ||
@@ -38,4 +39,4 @@ "urllib": "^2.22.0" | ||
"ci": { | ||
"version": "6, 7, 8" | ||
"version": "6, 8, 9" | ||
} | ||
} |
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
5244
57