]>
git.r.bdr.sh - rbdr/cologne/blob - lib/cologne/logger/file.js
e9a56e72071d1fdd658738a68d9809f51bf1a741
3 let fs
= require('fs');
5 let LogUtilities
= require('../log_utilities');
10 * @memberof Cologne.Logger
11 * @implements Cologne.ILogger
14 let FileLogger
= class FileLogger
{
15 constructor (config
) {
18 * Path to the file it will write to, must be readable.
22 * @memberof Cologne.Logger.File
29 * The formatter it will use to output the log. If not present it
30 * will output raw JSON
34 * @memberof Cologne.Logger.File
35 * @type Cologne.IFormatter
38 this.formatter
= null;
40 Object
.assign(this, config
|| {});
42 this._stream
= fs
.createWriteStream(this.file
, {flags: 'a'});
46 * Main entry point, for each incoming argument it will attempt to
47 * format and send to the stream to be written.
51 * @memberof Cologne.Logger.File
57 for (logObject
of arguments
) {
58 this._stream
.write(this.format(logObject
) + '\n');
64 return this.formatter
.format(logObject
);
67 return LogUtilities
.stringify(logObject
);
71 module
.exports
= FileLogger
;