]>
git.r.bdr.sh - rbdr/cologne/blob - lib/cologne/formatter/simple.js
48821fc597e1f1b12bc86c6f39e800dfd5ff327b
3 let LogUtilities
= require('../log_utilities');
6 * Simple formatter. Outputs a predefined format:
7 * `[{{_timestamp}}][{{_levelString}}] {{_from}}: {{message}}`;
9 * @memberof Cologne.Formatter
10 * @implements Cologne.IFormatter
13 let SimpleFormatter
= class SimpleFormatter
{
15 constructor (config
) {
18 * Flag that tells us whether or not to use ANSI color. Defaults to
23 * @memberof Cologne.Formatter.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 Cologne.Formatter.Simple
39 * @param {Cologne.tCologneLog} logObjet the log to format
40 * @return {String} the formatted object
43 let date
, levelString
;
45 date
= new Date(logObject
._timestamp
);
46 date
= date
.toISOString();
47 levelString
= this._colorize(logObject
._levelString
, logObject
._level
);
49 return `[${date}][${levelString}] ${logObject._from}: ${logObject.message}`;
52 _colorize (levelString
, level
) {
53 let escapeCode
, color
, reset
;
59 escapeCode
= String
.fromCharCode(27);
60 color
= escapeCode
+ LogUtilities
.getAnsiCode(LogUtilities
.getLevelAnsi(level
));
61 reset
= escapeCode
+ LogUtilities
.getAnsiCode('reset');
63 return color
+ levelString
+ reset
;
67 module
.exports
= SimpleFormatter
;