random bs
This commit is contained in:
parent
0e172dd73a
commit
c22eea56bd
@ -1,10 +1,10 @@
|
|||||||
|
/* eslint-disable no-control-regex */
|
||||||
const { transports: { File }} = require('winston');
|
const { transports: { File }} = require('winston');
|
||||||
const debug = require('diagnostics')('winston:file');
|
const debug = require('diagnostics')('winston:file');
|
||||||
const { MESSAGE } = require('triple-beam');
|
const { MESSAGE } = require('triple-beam');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const chalk = require('chalk');
|
|
||||||
|
|
||||||
const regex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
|
const regex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
||||||
|
|
||||||
class FileExtension extends File {
|
class FileExtension extends File {
|
||||||
|
|
||||||
@ -17,28 +17,28 @@ class FileExtension extends File {
|
|||||||
// when thinking about 3.x? Should silent be handled in the base
|
// when thinking about 3.x? Should silent be handled in the base
|
||||||
// TransportStream _write method?
|
// TransportStream _write method?
|
||||||
if (this.silent) {
|
if (this.silent) {
|
||||||
callback();
|
callback();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output stream buffer is full and has asked us to wait for the drain event
|
// Output stream buffer is full and has asked us to wait for the drain event
|
||||||
if (this._drain) {
|
if (this._drain) {
|
||||||
this._stream.once('drain', () => {
|
this._stream.once('drain', () => {
|
||||||
this._drain = false;
|
this._drain = false;
|
||||||
this.log(info, callback);
|
this.log(info, callback);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this._rotate) {
|
if (this._rotate) {
|
||||||
this._stream.once('rotate', () => {
|
this._stream.once('rotate', () => {
|
||||||
this._rotate = false;
|
this._rotate = false;
|
||||||
this.log(info, callback);
|
this.log(info, callback);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the raw string and append the expected EOL.
|
// Grab the raw string and append the expected EOL.
|
||||||
const output = `${info[MESSAGE]}${this.eol}`.replace(regex, '')
|
const output = `${info[MESSAGE]}${this.eol}`.replace(regex, '');
|
||||||
const bytes = Buffer.byteLength(output);
|
const bytes = Buffer.byteLength(output);
|
||||||
|
|
||||||
// After we have written to the PassThrough check to see if we need
|
// After we have written to the PassThrough check to see if we need
|
||||||
@ -47,27 +47,27 @@ class FileExtension extends File {
|
|||||||
// Remark: This gets called too early and does not depict when data
|
// Remark: This gets called too early and does not depict when data
|
||||||
// has been actually flushed to disk.
|
// has been actually flushed to disk.
|
||||||
function logged() {
|
function logged() {
|
||||||
this._size += bytes;
|
this._size += bytes;
|
||||||
this._pendingSize -= bytes;
|
this._pendingSize -= bytes;
|
||||||
|
|
||||||
debug('logged %s %s', this._size, output);
|
debug('logged %s %s', this._size, output);
|
||||||
this.emit('logged', info);
|
this.emit('logged', info);
|
||||||
|
|
||||||
// Do not attempt to rotate files while opening
|
// Do not attempt to rotate files while opening
|
||||||
if (this._opening) {
|
if (this._opening) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if we need to end the stream and create a new one.
|
// Check to see if we need to end the stream and create a new one.
|
||||||
if (!this._needsNewFile()) {
|
if (!this._needsNewFile()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// End the current stream, ensure it flushes and create a new one.
|
// End the current stream, ensure it flushes and create a new one.
|
||||||
// This could potentially be optimized to not run a stat call but its
|
// This could potentially be optimized to not run a stat call but its
|
||||||
// the safest way since we are supporting `maxFiles`.
|
// the safest way since we are supporting `maxFiles`.
|
||||||
this._rotate = true;
|
this._rotate = true;
|
||||||
this._endStream(() => this._rotateFile());
|
this._endStream(() => this._rotateFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of the pending bytes being written while files are opening
|
// Keep track of the pending bytes being written while files are opening
|
||||||
@ -77,18 +77,18 @@ class FileExtension extends File {
|
|||||||
if (this._opening
|
if (this._opening
|
||||||
&& !this.rotatedWhileOpening
|
&& !this.rotatedWhileOpening
|
||||||
&& this._needsNewFile(this._size + this._pendingSize)) {
|
&& this._needsNewFile(this._size + this._pendingSize)) {
|
||||||
this.rotatedWhileOpening = true;
|
this.rotatedWhileOpening = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const written = this._stream.write(output, logged.bind(this));
|
const written = this._stream.write(output, logged.bind(this));
|
||||||
if (!written) {
|
if (!written) {
|
||||||
this._drain = true;
|
this._drain = true;
|
||||||
this._stream.once('drain', () => {
|
this._stream.once('drain', () => {
|
||||||
this._drain = false;
|
this._drain = false;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(); // eslint-disable-line callback-return
|
callback(); // eslint-disable-line callback-return
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('written', written, this._drain);
|
debug('written', written, this._drain);
|
||||||
@ -96,7 +96,7 @@ class FileExtension extends File {
|
|||||||
this.finishIfEnding();
|
this.finishIfEnding();
|
||||||
|
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
get date() {
|
get date() {
|
||||||
return moment().format("MM-DD-YYYY hh:mm:ss");
|
return moment().format("MM-DD-YYYY hh:mm:ss");
|
||||||
|
Loading…
Reference in New Issue
Block a user