rotating-file-stream
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -0,1 +1,3 @@ | ||
* 2017-11-13 - v1.3.4 | ||
* __immutable__ option review | ||
* 2017-11-13 - v1.3.3 | ||
@@ -2,0 +4,0 @@ * Solved: [problem with TypeScript](https://github.com/iccicci/rotating-file-stream/issues/19) |
36
index.js
@@ -203,16 +203,13 @@ "use strict"; | ||
if(index === 1) | ||
this.last = this.name; | ||
try{ this.name = this.generator(now, index); } | ||
catch(e) { return this.emit("error", e); } | ||
var open = function() { | ||
var open = function(size) { | ||
this.size = size; | ||
this.open(); | ||
this.once("open", function() { | ||
if(! first) { | ||
this.emit("rotation", this.name); | ||
if(! first) | ||
this.emit("rotated", this.last); | ||
} | ||
this.last = this.name; | ||
this.interval(); | ||
@@ -223,7 +220,5 @@ }.bind(this)); | ||
fs.stat(this.name, function(err, stats) { | ||
this.size = 0; | ||
if(err) { | ||
if(err.code === "ENOENT") | ||
return open(); | ||
return open(0); | ||
@@ -236,8 +231,6 @@ return this.emit("error", err); | ||
this.size = stats.size; | ||
if(this.options.size && stats.size >= this.options.size) | ||
return this.immutate(first, index + 1, now); | ||
open(); | ||
open(stats.size); | ||
}.bind(this)); | ||
@@ -309,3 +302,3 @@ } | ||
self.stream = stream; | ||
self.emit("open"); | ||
self.emit("open", self.name); | ||
@@ -329,15 +322,12 @@ callback(); | ||
RotatingFileStream.prototype.rotate = function() { | ||
var mutable = this.options.rotate || ! this.options.immutable; | ||
this.size = 0; | ||
this.rotation = new Date(); | ||
this.emit("rotation"); | ||
this._clear(); | ||
this._close(mutable ? | ||
this.options.rotate ? | ||
this.classical.bind(this, this.options.rotate) : | ||
this.move.bind(this) : | ||
this.immutate.bind(this)); | ||
if(mutable) | ||
this.emit("rotation"); | ||
this._close(this.options.rotate ? | ||
this.classical.bind(this, this.options.rotate) : | ||
this.options.immutable ? | ||
this.immutate.bind(this) : | ||
this.move.bind(this)); | ||
}; | ||
@@ -344,0 +334,0 @@ |
{ | ||
"name": "rotating-file-stream", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Opens a stream.Writable to a file rotated by interval and/or size. A logrotate alternative.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -295,4 +295,5 @@ # rotating-file-stream | ||
stream.on('open', function() { | ||
stream.on('open', function(filename) { | ||
// no rotated file is open (emitted after each rotation as well) | ||
// filename: useful if immutable option is true | ||
}); | ||
@@ -306,5 +307,4 @@ | ||
stream.on('rotation', function(filename) { | ||
stream.on('rotation', function() { | ||
// rotation job started | ||
// filename: if immutable then newly generated file else null | ||
}); | ||
@@ -311,0 +311,0 @@ |
40402
779