egg-logrotater
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -11,14 +11,25 @@ 'use strict'; | ||
const logger = app.coreLogger; | ||
const rotateLogDirs = app.config.logger.rotateLogDirs; | ||
const messenger = app.messenger; | ||
exports.schedule = { | ||
type: 'worker', // 类型 为 `all` 的定时任务在到执行时间时所有的进程都会执行 | ||
cron: '0 0 * * *', // 直接指定执行的间隔,支持 ms 格式的字符串或者毫秒级别的数值 | ||
type: 'worker', // only one worker run this task | ||
cron: '0 0 * * *', // run every day at 00:00 | ||
}; | ||
exports.task = function* () { | ||
let logDirs = []; | ||
// try to use rotateLogDirs first | ||
if (app.config.logger.rotateLogDirs && app.config.logger.rotateLogDirs.length > 0) { | ||
logDirs = logDirs.concat(app.config.logger.rotateLogDirs); | ||
} | ||
// auto find all log dir | ||
for (const key in app.loggers) { | ||
const logDir = path.dirname(app.loggers[key].options.file); | ||
if (logDirs.indexOf(logDir) === -1) { | ||
logDirs.push(logDir); | ||
} | ||
} | ||
const maxDays = app.config.logrotater.maxDays; | ||
if (maxDays && maxDays > 0) { | ||
try { | ||
yield rotateLogDirs.map(logdir => removeExpiredLogFiles(logdir, maxDays)); | ||
yield logDirs.map(logdir => removeExpiredLogFiles(logdir, maxDays)); | ||
} catch (err) { | ||
@@ -30,3 +41,3 @@ logger.error(err); | ||
try { | ||
yield rotateLogDirs.map(logdir => renameLogfiles(logdir)); | ||
yield logDirs.map(logdir => renameLogfiles(logdir)); | ||
} catch (err) { | ||
@@ -37,5 +48,5 @@ logger.error(err); | ||
// tell every one to reload logger | ||
logger.info('[egg-logrotater] broadcast log-reload to workers'); | ||
messenger.sendToApp('log-reload'); | ||
messenger.sendToAgent('log-reload'); | ||
logger.info('[egg-logrotater] broadcast log-reload to workers, logDirs: %j', logDirs); | ||
app.messenger.sendToApp('log-reload'); | ||
app.messenger.sendToAgent('log-reload'); | ||
}; | ||
@@ -42,0 +53,0 @@ |
1.0.1 / 2016-08-10 | ||
================== | ||
* fix: auto find log file dirs to do rotate (#2) | ||
1.0.0 / 2016-07-26 | ||
@@ -3,0 +8,0 @@ ================== |
{ | ||
"name": "egg-logrotater", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "logrotater for egg", | ||
@@ -5,0 +5,0 @@ "eggPlugin": { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10904
183