]>
git.r.bdr.sh - rbdr/cologne/blob - lib/cologne/log_utilities.js
fc15a8aec0ef0eeb77348810e5687824f6f6dacd
3 let microtime
= require('microtime');
6 * Container object for utilities used by loggers.
14 * Returns the current timestamp in miliseconds as a floating point that
15 * includes fractions (ie. microseconds)
18 * @memberof Cologne.LogUtilities
19 * @return {Number} current time in miliseconds, including fractions.
22 return microtime
.nowDouble() * 1000;
26 * Stringifies objects, avoiding circular references.
29 * @memberof Cologne.LogUtilities
30 * @param {Object} object the object to stringify
31 * @return {String} the stringified object
33 stringify: function stringify(object
) {
38 return JSON
.stringify(object
, function (key
, value
) {
39 if (typeof value
=== 'object' && value
!== null) {
40 if (cache
.indexOf(value
) !== -1) {
41 return this._circularString
;
52 * Given an ansi keyword, it will return the appropriate code.
54 * @function getAnsiCode
55 * @memberof Cologne.LogUtilities
56 * @param {String} ansiString the name of the desired code
57 * @return {String} the ansi code
59 getAnsiCode: function getAnsiCode(ansiString
) {
79 case 'strikethrough_off':
117 case 'reset': // for informative purpouses
124 * Given a level, it will return the appropriate ansi keyword related
127 * @function getLevelAnsi
128 * @memberof Cologne.LogUtilities
129 * @param {number} level the level of the log
130 * @return {String} the ansi keyword
132 getLevelAnsi: function getLevelAnsi(level
) {
152 // String used as default circular reference.
153 LogUtilities
._circularString
= '[Circular]';
155 module
.exports
= LogUtilities
;