]>
git.r.bdr.sh - rbdr/cologne/blob - lib/formatters/simple.js
3 const Utilities
= require('../utilities');
6 * Simple formatter. Outputs a predefined format:
7 * `[{{_timestamp}}][{{_levelString}}] {{_from}}: {{message}}`;
10 * @implements IFormatter
13 module
.exports
= class SimpleFormatter
{
18 * Flag that tells us whether or not to use ANSI color. Defaults to
23 * @memberof Formatters.Simple
27 this.colorize
= false;
29 Object
.assign(this, config
|| {});
33 * Main entry point, it will read the incoming log object and convert
34 * it to the output string.
38 * @memberof Formatters.Simple
39 * @param {tCologneLog} logObjet the log to format
40 * @return {String} the formatted object
44 const date
= (new Date(Number(logObject
._timestamp
) / 1000000)).toISOString();
45 const levelString
= this._colorize(logObject
._levelString
, logObject
._level
);
47 return `[${date}][${levelString}] ${logObject._from}: ${logObject.message}`;
50 _colorize(levelString
, level
) {
56 const escapeCode
= String
.fromCharCode(27);
57 const color
= escapeCode
+ Utilities
.getAnsiCode(Utilities
.getLevelAnsi(level
));
58 const reset
= escapeCode
+ Utilities
.getAnsiCode('reset');
60 return color
+ levelString
+ reset
;