bunyan-rotating-file-stream
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -5,2 +5,8 @@ # bunyan Changelog | ||
## 1.0.5 | ||
- Restructured project | ||
- Moved to a properly named git repository with only this project's history in it | ||
- Added basic tests to excercise everything and make sure nothing is broken | ||
## 1.0.4 | ||
@@ -7,0 +13,0 @@ |
{ | ||
"name": "bunyan-rotating-file-stream", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "a rotating file stream for the bunyan logging system", | ||
"author": "Jim Tupper <npm@tupper.org.uk> (http://github.com/rcomian)", | ||
"main": "./lib/rotatingfilestream/index.js", | ||
"main": "./index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/Rcomian/bunyan-rotating-file-store.git" | ||
"url": "git://github.com/Rcomian/bunyan-rotating-file-stream.git" | ||
}, | ||
@@ -25,3 +25,6 @@ "engines": [ | ||
"optionalDependencies": {}, | ||
"devDependencies": {}, | ||
"devDependencies": { | ||
"mkdir-recursive": "^0.2.1", | ||
"rmdir": "^1.1.0" | ||
}, | ||
"dependencies": { | ||
@@ -28,0 +31,0 @@ "async": "^1.5.2", |
182
test.js
var bunyan = require('bunyan'); | ||
var RotatingFileStream = require('./lib/rotatingfilestream'); | ||
var _ = require('lodash'); | ||
var fs = require('fs'); | ||
var assert = require('assert'); | ||
var fx = require('mkdir-recursive'); | ||
var rmdir = require('rmdir'); | ||
var RotatingFileStream = require('./index'); | ||
var async = require('async'); | ||
var log = bunyan.createLogger({ | ||
name: 'foo', | ||
streams: [{ | ||
type: 'raw', | ||
stream: new RotatingFileStream({ | ||
path: 'foo.log', | ||
period: '1h', | ||
threshold: '1m', | ||
totalFiles: 2000, | ||
totalSize: '10m', | ||
gzip: true | ||
}) | ||
}] | ||
}); | ||
function runTest(options, next) { | ||
var rfs = RotatingFileStream(_.extend({}, { path: 'foo.log' }, options.stream)); | ||
var log = bunyan.createLogger({ | ||
name: 'foo', | ||
streams: [{ | ||
type: 'raw', | ||
stream: rfs | ||
}] | ||
}); | ||
var i = 0; | ||
var imax = 100000; | ||
var batchsize = 8; | ||
var ia = setInterval(function () { | ||
var i = 0; | ||
var batch = _.extend({}, { size: 8 }, options.batch); | ||
for (var j = 0; j < batchsize; j += 1) { | ||
log.info({node: 'a', i}); | ||
i += 1; | ||
var ia = setInterval(function () { | ||
for (var j = 0; j < batch.size; j += 1) { | ||
log.info({node: 'a', i}); | ||
i += 1; | ||
if (i >= imax) { | ||
if (typeof (batch.iterations) !== 'undefined' && i >= batch.iterations) { | ||
clearInterval(ia); | ||
rfs.destroy(); | ||
next(); | ||
return; | ||
} | ||
} | ||
}, 0); | ||
if (typeof (batch.duration) !== 'undefined') { | ||
setTimeout(function () | ||
{ | ||
clearInterval(ia); | ||
rfs.destroy(); | ||
next(); | ||
return; | ||
}, batch.duration); | ||
} | ||
} | ||
function ignoreMissing(next) { | ||
return function (err) { | ||
if (!err || err.code === 'ENOENT') { | ||
next(); | ||
} else { | ||
next(err); | ||
} | ||
} | ||
} | ||
}, 0); | ||
function basicthreshold(next) { | ||
var name = 'testlogs/' + 'basicthreshold'; | ||
async.series([ | ||
function (next) { rmdir(name, ignoreMissing(next)); }, | ||
function (next) { fx.mkdir(name, next); }, | ||
function (next) { runTest ({ | ||
stream: { path: name + '/test.log', threshold: '1m' }, | ||
batch: { iterations: 100000 } | ||
}, next); }, | ||
function (next) { | ||
var files = fs.readdirSync(name); | ||
assert.equal(13, files.length); | ||
console.log(name, 'passed'); | ||
next(); | ||
}, | ||
function (next) { rmdir(name, next); } | ||
], next); | ||
} | ||
function timerotation(next) { | ||
var name = 'testlogs/' + 'timerotation'; | ||
async.series([ | ||
function (next) { rmdir(name, ignoreMissing(next)); }, | ||
function (next) { fx.mkdir(name, next); }, | ||
function (next) { runTest ({ | ||
stream: { path: name + '/test.log', period: '1000ms' }, | ||
batch: { duration: 9500 } | ||
}, next); }, | ||
function (next) { | ||
var files = fs.readdirSync(name); | ||
assert.equal(10, files.length); | ||
console.log(name, 'passed'); | ||
next(); | ||
}, | ||
function (next) { rmdir(name, next); } | ||
], next); | ||
} | ||
function gzippedfiles(next) { | ||
var name = 'testlogs/' + 'gzippedfiles'; | ||
async.series([ | ||
function (next) { rmdir(name, ignoreMissing(next)); }, | ||
function (next) { fx.mkdir(name, next); }, | ||
function (next) { runTest ({ | ||
stream: { path: name + '/test.log', threshold: '1m', gzip: true }, | ||
batch: { iterations: 100000 } | ||
}, next); }, | ||
function (next) { | ||
var files = fs.readdirSync(name); | ||
assert.equal(13, files.length); | ||
assert.equal(12, _(files).filter( (f) => { return f.endsWith('.gz'); }).value().length); | ||
console.log(name, 'passed'); | ||
next(); | ||
}, | ||
function (next) { rmdir(name, next); } | ||
], next); | ||
} | ||
function totalsize(next) { | ||
var name = 'testlogs/' + 'totalsize'; | ||
async.series([ | ||
function (next) { rmdir(name, ignoreMissing(next)); }, | ||
function (next) { fx.mkdir(name, next); }, | ||
function (next) { runTest ({ | ||
stream: { path: name + '/test.log', threshold: '1m', totalSize: '10m' }, | ||
batch: { iterations: 100000 } | ||
}, next); }, | ||
function (next) { | ||
var files = fs.readdirSync(name); | ||
assert.equal(10, files.length); | ||
console.log(name, 'passed'); | ||
next(); | ||
}, | ||
function (next) { rmdir(name, next); } | ||
], next); | ||
} | ||
function totalfiles(next) { | ||
var name = 'testlogs/' + 'totalfiles'; | ||
async.series([ | ||
function (next) { rmdir(name, ignoreMissing(next)); }, | ||
function (next) { fx.mkdir(name, next); }, | ||
function (next) { runTest ({ | ||
stream: { path: name + '/test.log', threshold: '1m', totalFiles: 5 }, | ||
batch: { iterations: 100000 } | ||
}, next); }, | ||
function (next) { | ||
var files = fs.readdirSync(name); | ||
assert.equal(6, files.length); | ||
console.log(name, 'passed'); | ||
next(); | ||
}, | ||
function (next) { rmdir(name, next); } | ||
], next); | ||
} | ||
async.parallel([ | ||
basicthreshold, | ||
timerotation, | ||
gzippedfiles, | ||
totalsize, | ||
totalfiles, | ||
], function (err) { | ||
if (err) console.log(err); | ||
}); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
767
45167
2
19
4
1