egg-logrotator
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -20,3 +20,3 @@ 'use strict'; | ||
* getRotateFiles() { | ||
async getRotateFiles() { | ||
const files = new Map(); | ||
@@ -41,7 +41,7 @@ const loggers = this.app.loggers; | ||
for (const dir of rotateLogDirs) { | ||
const exists = yield fs.exists(dir); | ||
const exists = await fs.exists(dir); | ||
if (!exists) continue; | ||
try { | ||
const names = yield fs.readdir(dir); | ||
const names = await fs.readdir(dir); | ||
for (const name of names) { | ||
@@ -48,0 +48,0 @@ if (!name.endsWith('.log')) { |
@@ -13,3 +13,3 @@ 'use strict'; | ||
* getRotateFiles() { | ||
async getRotateFiles() { | ||
const files = new Map(); | ||
@@ -19,3 +19,3 @@ const filesRotateByHour = this.app.config.logrotator.filesRotateByHour || []; | ||
for (const logPath of filesRotateByHour) { | ||
const exists = yield fs.exists(logPath); | ||
const exists = await fs.exists(logPath); | ||
if (!exists) { | ||
@@ -22,0 +22,0 @@ continue; |
@@ -21,4 +21,4 @@ 'use strict'; | ||
* rotate() { | ||
const files = yield this.getRotateFiles(); | ||
async rotate() { | ||
const files = await this.getRotateFiles(); | ||
assert(files instanceof Map, 'getRotateFiles should return a Map'); | ||
@@ -29,3 +29,3 @@ const rotatedFile = []; | ||
debug('rename from %s to %s', file.srcPath, file.targetPath); | ||
yield renameOrDelete(file.srcPath, file.targetPath); | ||
await renameOrDelete(file.srcPath, file.targetPath); | ||
rotatedFile.push(`${file.srcPath} -> ${file.targetPath}`); | ||
@@ -53,11 +53,11 @@ } catch (err) { | ||
// rename from srcPath to targetPath, for example foo.log.1 > foo.log.2 | ||
function* renameOrDelete(srcPath, targetPath) { | ||
async function renameOrDelete(srcPath, targetPath) { | ||
if (srcPath === targetPath) { | ||
return; | ||
} | ||
const srcExists = yield fs.exists(srcPath); | ||
const srcExists = await fs.exists(srcPath); | ||
if (!srcExists) { | ||
return; | ||
} | ||
const targetExists = yield fs.exists(targetPath); | ||
const targetExists = await fs.exists(targetPath); | ||
// if target file exists, then throw | ||
@@ -69,3 +69,3 @@ // because the target file always be renamed first. | ||
} | ||
yield fs.rename(srcPath, targetPath); | ||
await fs.rename(srcPath, targetPath); | ||
} |
@@ -13,3 +13,3 @@ 'use strict'; | ||
* getRotateFiles() { | ||
async getRotateFiles() { | ||
const files = new Map(); | ||
@@ -20,3 +20,3 @@ const filesRotateBySize = this.app.config.logrotator.filesRotateBySize || []; | ||
for (const logPath of filesRotateBySize) { | ||
const exists = yield fs.exists(logPath); | ||
const exists = await fs.exists(logPath); | ||
if (!exists) { | ||
@@ -26,3 +26,3 @@ continue; | ||
try { | ||
const stat = yield fs.stat(logPath); | ||
const stat = await fs.stat(logPath); | ||
if (stat.size >= maxFileSize) { | ||
@@ -32,5 +32,5 @@ this.logger.info(`[egg-logrotator] file ${logPath} reach the maximum file size, current size: ${stat.size}, max size: ${maxFileSize}`); | ||
const maxFileName = `${logPath}.${maxFiles}`; | ||
const maxExists = yield fs.exists(maxFileName); | ||
const maxExists = await fs.exists(maxFileName); | ||
if (maxExists) { | ||
yield fs.unlink(maxFileName); | ||
await fs.unlink(maxFileName); | ||
} | ||
@@ -37,0 +37,0 @@ this._setFile(logPath, files); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
* task() { | ||
async task() { | ||
const logger = app.coreLogger; | ||
@@ -28,3 +28,4 @@ const logDirs = []; | ||
try { | ||
yield logDirs.map(logdir => removeExpiredLogFiles(logdir, maxDays, logger)); | ||
const tasks = logDirs.map(logdir => removeExpiredLogFiles(logdir, maxDays, logger)); | ||
await Promise.all(tasks); | ||
} catch (err) { | ||
@@ -40,4 +41,4 @@ logger.error(err); | ||
// remove expired log files: xxx.log.YYYY-MM-DD | ||
function* removeExpiredLogFiles(logdir, maxDays, logger) { | ||
const files = yield fs.readdir(logdir); | ||
async function removeExpiredLogFiles(logdir, maxDays, logger) { | ||
const files = await fs.readdir(logdir); | ||
const expriedDate = moment().subtract(maxDays, 'days').startOf('date'); | ||
@@ -61,11 +62,10 @@ const names = files.filter(file => { | ||
yield names.map(name => function* () { | ||
await Promise.all(names.map(name => { | ||
const logfile = path.join(logdir, name); | ||
try { | ||
yield fs.unlink(logfile); | ||
} catch (err) { | ||
err.message = `[egg-logrotator] remove logfile ${logfile} error, ${err.message}`; | ||
logger.error(err); | ||
} | ||
}); | ||
return fs.unlink(logfile) | ||
.catch(err => { | ||
err.message = `[egg-logrotator] remove logfile ${logfile} error, ${err.message}`; | ||
logger.error(err); | ||
}); | ||
})); | ||
} |
@@ -16,4 +16,4 @@ 'use strict'; | ||
* task() { | ||
yield rotator.rotate(); | ||
async task() { | ||
await rotator.rotate(); | ||
}, | ||
@@ -20,0 +20,0 @@ |
@@ -17,4 +17,4 @@ 'use strict'; | ||
* task() { | ||
yield rotator.rotate(); | ||
async task() { | ||
await rotator.rotate(); | ||
}, | ||
@@ -21,0 +21,0 @@ |
@@ -17,6 +17,6 @@ 'use strict'; | ||
* task() { | ||
yield rotator.rotate(); | ||
async task() { | ||
await rotator.rotate(); | ||
}, | ||
}; | ||
}; |
3.0.0 / 2017-11-10 | ||
================== | ||
**others** | ||
* [[`6b4e6e5`](http://github.com/eggjs/egg-logrotater/commit/6b4e6e58ee5aab5310059bde59f3c89fdba2d3ae)] - refactor: use async function and support egg@2 (#13) (Yiyu He <<dead_horse@qq.com>>) | ||
2.3.0 / 2017-11-02 | ||
@@ -3,0 +9,0 @@ ================== |
{ | ||
"name": "egg-logrotator", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "logrotator for egg", | ||
@@ -17,3 +17,3 @@ "eggPlugin": { | ||
"debug": "^3.1.0", | ||
"moment": "^2.19.0", | ||
"moment": "^2.19.1", | ||
"mz": "^2.7.0" | ||
@@ -28,8 +28,8 @@ }, | ||
"devDependencies": { | ||
"autod": "^2.9.0", | ||
"egg": "^1.9.0", | ||
"autod": "^2.10.1", | ||
"egg": "next", | ||
"egg-bin": "^4.3.5", | ||
"egg-ci": "^1.8.0", | ||
"egg-mock": "^3.13.0", | ||
"eslint": "^4.8.0", | ||
"egg-mock": "^3.13.1", | ||
"eslint": "^4.10.0", | ||
"eslint-config-egg": "^5.1.1", | ||
@@ -41,3 +41,3 @@ "glob": "^7.1.2", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -54,3 +54,3 @@ "scripts": { | ||
"ci": { | ||
"version": "6, 7" | ||
"version": "8, 9" | ||
}, | ||
@@ -57,0 +57,0 @@ "repository": { |
@@ -90,4 +90,4 @@ # egg-logrotator | ||
}, | ||
* task() { | ||
yield rotator.rotate(); | ||
async task() { | ||
await rotator.rotate(); | ||
} | ||
@@ -101,3 +101,3 @@ }; | ||
// LogRotator will rename ksrcPath to targetPath | ||
* getRotateFiles() { | ||
async getRotateFiles() { | ||
const files = new Map(); | ||
@@ -123,2 +123,1 @@ const srcPath = '/home/admin/foo.log'; | ||
[MIT](https://github.com/eggjs/egg-logrotator/blob/master/LICENSE) | ||
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
19892
16
121
1
Updatedmoment@^2.19.1