bunyan-rotating-file-stream
Advanced tools
Comparing version 1.5.1 to 1.5.2
# bunyan Changelog | ||
## 1.5.2 | ||
- Expanded node version compatibility and making a statement about which versions of node we offically support- `0.12.9`, `0.12.latest`, `4.latest`, `5.latest`. | ||
- Full passing test suites running against each version using `nvm`. | ||
- Stress test in place, needs tuning. | ||
## 1.5.1 | ||
@@ -4,0 +12,0 @@ |
56
index.js
// Utility to orchestrate the rotating file system object and its triggers. | ||
'use strict'; | ||
var DedupeRotatingFileStream = require('./lib/deduperotatingfilestream'); | ||
var RotatingFileStream = require('./lib/rotatingfilestream'); | ||
var PeriodTrigger = require('./lib/periodtrigger'); | ||
@@ -10,22 +10,48 @@ var InitialPeriodTrigger = require('./lib/initialperiodtrigger'); | ||
function RotatingFileStreamFactory(options) { | ||
var rfs = DedupeRotatingFileStream(options); | ||
var path = require('path'); | ||
if (options.period) { | ||
var periodTrigger = PeriodTrigger(options); | ||
TriggerAdapter(periodTrigger, rfs); | ||
} | ||
var existingFilesStreams = {}; | ||
if (options.period && options.rotateExisting) { | ||
var initialPeriodTrigger = InitialPeriodTrigger(options); | ||
TriggerAdapter(initialPeriodTrigger, rfs); | ||
function RotatingFileStreamFactory(options) { | ||
if (typeof (options.path) !== 'string') { | ||
throw new Error('Must provide a string for path'); | ||
} | ||
if (options.threshold) { | ||
var thresholdTrigger = ThresholdTrigger(options); | ||
TriggerAdapter(thresholdTrigger, rfs); | ||
options.path = path.resolve(options.path); | ||
var rfs = existingFilesStreams[options.path]; | ||
if (!rfs) { | ||
rfs = RotatingFileStream(options); | ||
existingFilesStreams[options.path] = rfs; | ||
rfs.once('shutdown', function () { | ||
existingFilesStreams[options.path] = null; | ||
}); | ||
if (options.period) { | ||
var periodTrigger = PeriodTrigger(options); | ||
TriggerAdapter(periodTrigger, rfs); | ||
} | ||
if (options.period && options.rotateExisting) { | ||
var initialPeriodTrigger = InitialPeriodTrigger(options); | ||
TriggerAdapter(initialPeriodTrigger, rfs); | ||
} | ||
if (options.threshold) { | ||
var thresholdTrigger = ThresholdTrigger(options); | ||
TriggerAdapter(thresholdTrigger, rfs); | ||
} | ||
rfs.initialise(); | ||
} else if (options.shared !== true || | ||
existingFilesStreams[options.path].shared !== true) { | ||
throw new Error('You should not create multiple rotating file ' + | ||
'streams against the same file: ' + options.path); | ||
} | ||
rfs.initialise(); | ||
return rfs; | ||
@@ -32,0 +58,0 @@ } |
@@ -64,3 +64,3 @@ var fs = require('fs'); | ||
next(err, { | ||
stat, | ||
stat: stat, | ||
path: fullpath | ||
@@ -144,3 +144,5 @@ }); | ||
function moveIntermediateFiles(next) { | ||
setImmediate(function () { next(); }); | ||
process.nextTick(function () { | ||
next(); | ||
}); | ||
}; | ||
@@ -154,3 +156,3 @@ | ||
} else { | ||
result = Object.assign({}, parsedPath); | ||
result = _.extend({}, parsedPath); | ||
if (nonce === 0) { | ||
@@ -261,6 +263,6 @@ result.name = result.name | ||
return { | ||
getStreamFilepath, | ||
newStreamFilepath, | ||
deleteFiles, | ||
moveIntermediateFiles | ||
getStreamFilepath: getStreamFilepath, | ||
newStreamFilepath: newStreamFilepath, | ||
deleteFiles: deleteFiles, | ||
moveIntermediateFiles: moveIntermediateFiles | ||
}; | ||
@@ -267,0 +269,0 @@ } |
@@ -38,4 +38,4 @@ 'use strict'; | ||
const unzippedPath = fileops.getStreamFilepath(false); | ||
const zippedPath = fileops.getStreamFilepath(true); | ||
var unzippedPath = fileops.getStreamFilepath(false); | ||
var zippedPath = fileops.getStreamFilepath(true); | ||
@@ -131,3 +131,3 @@ fs.createReadStream(unzippedPath) | ||
fileops.deleteFiles, | ||
initialiseNewFile({ startNewFile }) | ||
initialiseNewFile({ startNewFile: startNewFile }) | ||
], function (err) { | ||
@@ -142,4 +142,4 @@ callback(err, stream, streamPath); | ||
return _.extend({}, { | ||
initialise, | ||
rotate, | ||
initialise: initialise, | ||
rotate: rotate, | ||
end: shutdownCurrentStream | ||
@@ -146,0 +146,0 @@ }, base); |
@@ -58,6 +58,6 @@ // Just emits "rotate" events at the right time. | ||
return _.extend({}, { | ||
newFile, | ||
logWrite, | ||
shutdown, | ||
checkIfRotationNeeded}, | ||
newFile: newFile, | ||
logWrite: logWrite, | ||
shutdown: shutdown, | ||
checkIfRotationNeeded: checkIfRotationNeeded}, | ||
base); | ||
@@ -64,0 +64,0 @@ }; |
@@ -10,4 +10,4 @@ 'use strict'; | ||
const maxQueueLength = 100000; | ||
const queueClearingThreshold = 0.8; | ||
var maxQueueLength = 100000; | ||
var queueClearingThreshold = 0.8; | ||
var throwLogsAway = false; | ||
@@ -133,9 +133,9 @@ | ||
return _.extend({}, { | ||
push, | ||
paused, | ||
push: push, | ||
paused: paused, | ||
pause: queue.pause, | ||
resume: queue.resume, | ||
unshift: queue.unshift, | ||
join, | ||
isEmpty | ||
join: join, | ||
isEmpty: isEmpty | ||
}, base); | ||
@@ -142,0 +142,0 @@ } |
@@ -156,6 +156,6 @@ var fs = require('fs'); | ||
return { | ||
getStreamFilepath, | ||
newStreamFilepath, | ||
deleteFiles, | ||
moveIntermediateFiles | ||
getStreamFilepath: getStreamFilepath, | ||
newStreamFilepath: newStreamFilepath, | ||
deleteFiles: deleteFiles, | ||
moveIntermediateFiles: moveIntermediateFiles | ||
}; | ||
@@ -162,0 +162,0 @@ } |
@@ -65,2 +65,2 @@ 'use strict'; | ||
module.exports = { parseSize, parsePeriod }; | ||
module.exports = { parseSize: parseSize, parsePeriod: parsePeriod }; |
@@ -62,5 +62,9 @@ // Just emits "rotate" events at the right time. | ||
return _.extend({}, {newFile, logWrite, shutdown}, base); | ||
return _.extend({}, { | ||
newFile: newFile, | ||
logWrite: logWrite, | ||
shutdown: shutdown | ||
}, base); | ||
}; | ||
module.exports = PeriodRotateTrigger; |
@@ -16,2 +16,3 @@ /* global Buffer */ | ||
var FileRotator = require('./filerotator'); | ||
var semver = require('semver'); | ||
@@ -22,10 +23,16 @@ var bunyan = require('bunyan'); | ||
// There is an annoying bug where setImmediate sometimes doesn't fire. | ||
// Fixed in node v5 | ||
var nextTick = semver.gt(process.version, '5.0.0') ? | ||
setImmediate : | ||
function (next) { setTimeout(next, 0); }; | ||
function RotatingFileStream(options) { | ||
var base = new EventEmitter(); | ||
const gzip = Boolean(options.gzip); | ||
const totalSize = optionParser.parseSize(options.totalSize); | ||
const totalFiles = options.totalFiles; | ||
const path = options.path; | ||
const shared = options.shared; | ||
var gzip = Boolean(options.gzip); | ||
var totalSize = optionParser.parseSize(options.totalSize); | ||
var totalFiles = options.totalFiles; | ||
var path = options.path; | ||
var shared = options.shared; | ||
@@ -118,3 +125,3 @@ var rotator = FileRotator(path, totalFiles, totalSize, gzip); | ||
var emitinfo = { | ||
logSize: writeBuffer.byteLength, | ||
logSize: writeBuffer.length, | ||
logstr: str | ||
@@ -147,5 +154,3 @@ }; | ||
setImmediate(function () { | ||
callback(); | ||
}); | ||
nextTick(callback); | ||
} | ||
@@ -243,11 +248,11 @@ | ||
return _.extend({}, { | ||
stream, | ||
initialise, | ||
rotate, | ||
write, | ||
end, | ||
destroy, | ||
destroySoon, | ||
join, | ||
shared | ||
stream: stream, | ||
initialise: initialise, | ||
rotate: rotate, | ||
write: write, | ||
end: end, | ||
destroy: destroy, | ||
destroySoon: destroySoon, | ||
join: join, | ||
shared: shared | ||
}, base); | ||
@@ -254,0 +259,0 @@ } |
@@ -61,5 +61,5 @@ 'use strict'; | ||
return { clear }; | ||
return { clear: clear }; | ||
} | ||
module.exports = setLongTimeout; |
@@ -36,5 +36,9 @@ 'use strict'; | ||
return _.extend({}, {newFile, logWrite, shutdown}, base); | ||
return _.extend({}, { | ||
newFile: newFile, | ||
logWrite: logWrite, | ||
shutdown: shutdown | ||
}, base); | ||
} | ||
module.exports = ThresholdTrigger; |
@@ -34,5 +34,5 @@ 'use strict'; | ||
return { onShutdown }; | ||
return { onShutdown: onShutdown }; | ||
} | ||
module.exports = TriggerAdapter; |
{ | ||
"name": "bunyan-rotating-file-stream", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "a rotating file stream for the bunyan logging system", | ||
@@ -25,4 +25,7 @@ "author": "Jim Tupper <npm@tupper.org.uk> (http://github.com/rcomian)", | ||
"devDependencies": { | ||
"mkdir-recursive": "^0.2.1", | ||
"bunyan": "^1.7.1", | ||
"js-combinatorics": "^0.5.0", | ||
"mkdirp": "^0.5.1", | ||
"rmdir": "^1.1.0", | ||
"uuid": "^2.0.1", | ||
"why-is-node-running": "^1.2.1" | ||
@@ -33,4 +36,5 @@ }, | ||
"lodash": "^4.2.1", | ||
"semver": "^5.1.0", | ||
"strftime": "^0.9.2" | ||
} | ||
} |
@@ -24,3 +24,20 @@ Bunyan Rotating File Stream is a stream component for the logging system "node bunyan" that provides rich and flexible control over your log files. | ||
## 1.5.2 Compatibility | ||
Implemented tests and strategies to support specific node versions: | ||
* 0.12.9 | ||
* 0.12.*latest* | ||
* 4.*latest* | ||
* 5.*latest* | ||
*0.10 and earlier* | ||
Not supported as it is missing a lot of useful path processing features. Whilst we could patch this with inline code and npm packages, I think it's a shame to have these hanging around when the functionality will be built into all future versions of node. | ||
*0.12* | ||
Is supported, but it's performance cannot keep up with the latest versions of node. I've had to reduce the stress involved when running tests to allow old `0.12` to keep up. | ||
## 1.5 Templates Release | ||
@@ -42,2 +59,5 @@ | ||
We can now regularly run feature tests against all supported versions of node. | ||
# Planned Future Features | ||
@@ -44,0 +64,0 @@ |
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
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
259059
472
347
6
4
6
3303
+ Addedsemver@^5.1.0
+ Addedsemver@5.7.2(transitive)