receive both the "message" and the "curlCommand". Added a "tracer" logger which allows you to create log files that a executable scripts. Those scripts will write all of the log messages as script comments, and not comment out the curlCommands, so that they can trace their application and use the generated script to recreate the issue. Most changes are simply cased by adding the "unused" rule to jshint.
42 lines
1.1 KiB
JavaScript
Executable File
42 lines
1.1 KiB
JavaScript
Executable File
/**
|
|
* Logger that writes to a file
|
|
*
|
|
* @class Loggers.File
|
|
* @extends StreamLogger
|
|
* @constructor
|
|
* @param {Object} config - The configuration for the Logger (See LoggerAbstract for generic options)
|
|
* @param {String} config.path - The location to write
|
|
* @param {Log} bridge - The object that triggers logging events, which we will record
|
|
*/
|
|
|
|
module.exports = File;
|
|
|
|
var StreamLogger = require('./stream');
|
|
var _ = require('../utils');
|
|
var fs = require('fs');
|
|
|
|
function File(config, bridge) {
|
|
// setup the stream before calling the super
|
|
this.path = config.path || 'elasticsearch.log';
|
|
config.stream = fs.createWriteStream(this.path, {
|
|
flags: 'a',
|
|
encoding: 'utf8'
|
|
});
|
|
|
|
// call my super
|
|
StreamLogger.call(this, config, bridge);
|
|
}
|
|
_.inherits(File, StreamLogger);
|
|
|
|
File.prototype.onProcessExit = _.handler(function () {
|
|
// flush the write buffer to disk
|
|
var writeBuffer = this.stream._writableState.buffer;
|
|
var out = '';
|
|
if (writeBuffer) {
|
|
writeBuffer.forEach(function (buffered) {
|
|
out += buffered.chunk.toString();
|
|
});
|
|
fs.appendFileSync(this.path, out);
|
|
}
|
|
});
|