Socket
Socket
Sign inDemoInstall

bunyan-rotating-file-stream

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bunyan-rotating-file-stream - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

lib/deduperotatingfilestream.js

4

CHANGES.md
# bunyan Changelog
## 1.3.0
- It appears to be a very common problem that multiple rotating file streams are created against the same file. This version should resolve this issue when done within the same process by caching and returning the first rotating stream created.
## 1.2.1

@@ -4,0 +8,0 @@

4

index.js
// Utility to orchestrate the rotating file system object and its triggers.
'use strict';
var RotatingFileStream = require('./lib/rotatingfilestream');
var DedupeRotatingFileStream = require('./lib/deduperotatingfilestream');
var PeriodTrigger = require('./lib/periodtrigger');

@@ -11,3 +11,3 @@ var InitialPeriodTrigger = require('./lib/initialperiodtrigger');

function RotatingFileStreamFactory(options) {
var rfs = RotatingFileStream(options);
var rfs = DedupeRotatingFileStream(options);

@@ -14,0 +14,0 @@ if (options.period) {

@@ -183,10 +183,12 @@ 'use strict';

base.emit('closefile');
var streamCopy = stream;
stream.end(function () {
streamCopy.removeListener('error', streamErrorHandler);
if (next) {
next();
}
});
stream = null;
if (stream) {
var streamCopy = stream;
stream.end(function () {
streamCopy.removeListener('error', streamErrorHandler);
if (next) {
next();
}
});
stream = null;
}
};

@@ -222,5 +224,9 @@

return _.extend({}, { initialise, rotate, end: shutdownCurrentStream }, base);
return _.extend({}, {
initialise,
rotate,
end: shutdownCurrentStream
}, base);
}
module.exports = FileRotator;

@@ -12,3 +12,3 @@ // Just emits "rotate" events at the right time.

var setLongTimeout = require ('./setlongtimeout');
var setLongTimeout = require('./setlongtimeout');

@@ -15,0 +15,0 @@ var _DEBUG = false;

@@ -8,2 +8,3 @@ // A rotating file stream will just

var fs = require('fs');
var iopath = require('path');
var async = require('async');

@@ -23,6 +24,2 @@ var _ = require('lodash');

if (typeof (options.path) !== 'string') {
throw new Error('Must provide a string for path');
}
const gzip = Boolean(options.gzip);

@@ -32,2 +29,3 @@ const totalSize = optionParser.parseSize(options.totalSize);

const path = options.path;
const shared = options.shared;

@@ -133,3 +131,6 @@ var rotator = FileRotator(path, totalFiles, totalSize, gzip);

function end(s) {
stream.end();
writeQueue.pause();
rotator.end(function () {
base.emit('shutdown');
});
};

@@ -139,5 +140,3 @@

writeQueue.pause();
if (stream) {
stream.destroy();
}
rotator.end();
base.emit('shutdown');

@@ -148,5 +147,3 @@ };

writeQueue.pause();
if (stream) {
stream.destroy();
}
rotator.end();
base.emit('shutdown');

@@ -157,5 +154,9 @@ };

writeQueue.join(function () {
rotator.end(cb);
rotator.end(function () {
base.emit('shutdown');
if (cb) {
cb();
}
});
});
}

@@ -171,3 +172,4 @@

destroySoon,
join
join,
shared
}, base);

@@ -174,0 +176,0 @@ }

{
"name": "bunyan-rotating-file-stream",
"version": "1.2.1",
"version": "1.3.0",
"description": "a rotating file stream for the bunyan logging system",

@@ -5,0 +5,0 @@ "author": "Jim Tupper <npm@tupper.org.uk> (http://github.com/rcomian)",

@@ -13,4 +13,4 @@ Bunyan is **a simple and fast JSON logging library** for node.js services:

rotateExisting: true, // Give ourselves a clean file when we start up, based on period
threshold: 10m, // Rotate log files larger than 10 megabytes
totalSize: 20m, // Don't keep more than 20mb of archived log files
threshold: '10m', // Rotate log files larger than 10 megabytes
totalSize: '20m', // Don't keep more than 20mb of archived log files
gzip: true // Compress the archive log files to save space

@@ -24,2 +24,11 @@ })

## 1.3
It's a very common programming error to accidentally create 2 rotating file streams against the same log file.
By default, we detect and disallow this option, throwing an exception as it normally means that a mistake has been made.
If, however, you really want to be able to do this, we can cache the file streams and return the original one
each time. To do this add `shared: true` to the list of options when creating each file stream.
Either way, it is now not possible to create 2 rotating file streams against the same file.
## 1.2

@@ -91,4 +100,4 @@

rotateExisting: true, // Give ourselves a clean file when we start up, based on period
threshold: 10m, // Rotate log files larger than 10 megabytes
totalSize: 20m, // Don't keep more than 20mb of archived log files
threshold: '10m', // Rotate log files larger than 10 megabytes
totalSize: '20m', // Don't keep more than 20mb of archived log files
gzip: true // Compress the archive log files to save space

@@ -95,0 +104,0 @@ })

@@ -201,2 +201,27 @@ var bunyan = require('bunyan');

function multiplerotatorsonsamefile(next) {
var name = 'testlogs/' + 'multiplerotatorsonsamefile';
async.series([
function (next) { rmdir(name, ignoreMissing(next)); },
function (next) { fx.mkdir(name, next); },
function (next) {
runTest (name, {
stream: { path: name + '/test.log', period: '1000ms', shared: true },
batch: { duration: 9500 }
}, next);
// Setup the second rotator
RotatingFileStream({ path: name + '/test.log', period: '1000ms', shared: true });
},
function (next) {
var files = fs.readdirSync(name);
assert.equal(10, files.length);
console.log(name, 'passed');
next();
},
function (next) { rmdir(name, ignoreMissing(next)); }
], next);
}
function checkrotationofoldfile(next) {

@@ -329,3 +354,4 @@ var name = 'testlogs/' + 'checkrotationofoldfile';

checksetlongtimeoutclear,
checksetlongtimeoutclearnormalperiods
checksetlongtimeoutclearnormalperiods,
multiplerotatorsonsamefile
], function (err) {

@@ -332,0 +358,0 @@ if (err) console.log(err);

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc