]>
git.r.bdr.sh - rbdr/cologne/blob - lib/loggers/file.js
50a251e1c58ab7a500b322c1aa76de91c990e324
3 const Fs
= require('fs');
4 const Utilities
= require('../utilities');
13 module
.exports
= class FileLogger
{
17 * Path to the file it will write to, must be readable.
21 * @memberof Loggers.File
28 * The formatter it will use to output the log. If not present it
29 * will output raw JSON
33 * @memberof Loggers.File
37 this.formatter
= null;
39 Object
.assign(this, config
);
41 this._stream
= Fs
.createWriteStream(this.file
, { flags: 'a' });
45 * Main entry point, for each incoming argument it will attempt to
46 * format and send to the stream to be written.
50 * @memberof Loggers.File
55 for (const log
of logs
) {
56 this._stream
.write(this._format(log
) + '\n');
63 return this.formatter
.format(logObject
);
66 return Utilities
.stringify(logObject
);