Socket
Socket
Sign inDemoInstall

bunyan-rotating-file-stream

Package Overview
Dependencies
24
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 1.0.5

index.js

6

CHANGES.md

@@ -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 @@

11

package.json
{
"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",

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);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc