#117 add warning about using rotating-file and cluster together
This commit is contained in:
parent
865cec6a6d
commit
2c2459df2f
2 changed files with 20 additions and 5 deletions
13
README.md
13
README.md
|
@ -643,13 +643,22 @@ used for anything else.</td>
|
|||
|
||||
## stream type: `rotating-file`
|
||||
|
||||
**WARNING:** Users of Bunyan's `rotating-file` should (a) be using at least
|
||||
bunyan 0.23.1 (with the fix for [this
|
||||
**WARNING on node 0.8 usage:** Users of Bunyan's `rotating-file` should (a) be
|
||||
using at least bunyan 0.23.1 (with the fix for [this
|
||||
issue](https://github.com/trentm/node-bunyan/pull/97)), and (b) should use at
|
||||
least node 0.10 (node 0.8 does not support the `unref()` method on
|
||||
`setTimeout(...)` needed for the mentioned fix). The symptom is that process
|
||||
termination will hang for up to a full rotation period.
|
||||
|
||||
**WARNING on [cluster](http://nodejs.org/docs/latest/api/all.html#all_cluster)
|
||||
usage:** Using Bunyan's `rotating-file` stream with node.js's "cluster" module
|
||||
can result in unexpected file rotation. You must not have multiple processes
|
||||
in the cluster logging to the same file path. In other words, you must have
|
||||
a separate log file path for the master and each worker in the cluster.
|
||||
Alternatively, consider using a system file rotation facility such as
|
||||
`logrotate` on Linux or `logadm` on SmartOS/Illumos. See
|
||||
[this comment on issue #117](https://github.com/trentm/node-bunyan/issues/117#issuecomment-44804938)
|
||||
for details.
|
||||
|
||||
A `type === 'rotating-file'` is a file stream that handles file automatic
|
||||
rotation.
|
||||
|
|
|
@ -1107,7 +1107,10 @@ RotatingFileStream.prototype.rotate = function rotate() {
|
|||
var self = this;
|
||||
var _DEBUG = false;
|
||||
|
||||
if (_DEBUG) console.log('-- [%s] rotating %s', new Date(), self.path);
|
||||
if (_DEBUG) {
|
||||
console.log('-- [%s, pid=%s] rotating %s',
|
||||
new Date(), process.pid, self.path);
|
||||
}
|
||||
if (self.rotating) {
|
||||
throw new TypeError('cannot start a rotation when already rotating');
|
||||
}
|
||||
|
@ -1142,7 +1145,10 @@ RotatingFileStream.prototype.rotate = function rotate() {
|
|||
if (!exists) {
|
||||
moves();
|
||||
} else {
|
||||
if (_DEBUG) console.log('mv %s %s', before, after);
|
||||
if (_DEBUG) {
|
||||
console.log('[pid %s] mv %s %s',
|
||||
process.pid, before, after);
|
||||
}
|
||||
mv(before, after, function (mvErr) {
|
||||
if (mvErr) {
|
||||
self.emit('error', mvErr);
|
||||
|
@ -1156,7 +1162,7 @@ RotatingFileStream.prototype.rotate = function rotate() {
|
|||
}
|
||||
|
||||
function finish() {
|
||||
if (_DEBUG) console.log('open %s', self.path);
|
||||
if (_DEBUG) console.log('[pid %s] open %s', process.pid, self.path);
|
||||
self.stream = fs.createWriteStream(self.path,
|
||||
{flags: 'a', encoding: 'utf8'});
|
||||
var q = self.rotQueue, len = q.length;
|
||||
|
|
Loading…
Reference in a new issue