X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/bdedb5e54032363de8afa322fadae0e2cb2132d0..db6bc3cb0117030b2d31d55850d91f58248a8e81:/lib/formatters/token.js?ds=inline diff --git a/lib/formatters/token.js b/lib/formatters/token.js index 40d4f59..4fa7d57 100644 --- a/lib/formatters/token.js +++ b/lib/formatters/token.js @@ -1,79 +1,58 @@ -(function (global) { - var Module; - - // Load up dependencies - if (typeof require === 'function') { - var Ne = require('neon'); - Module = Ne.Module; - } else { - Module = global.Module; - } - - var Cobalt = {}; - Module(Cobalt, 'Formatter')({}); - - Cobalt.Formatter.Token = Module(Cobalt.Formatter, 'Token')({ - formatString : "{{message}}", - replaceRule : /{{(.*?)}}/g, - separatorLength : 60, - separatorType : "-", - format : function (logObject, opts){ - var indent, indentSize, - separatorLength, separatorType, - output; - indentSize = logObject._indentLevel || 0; - - indent = Array(indentSize + 1).join(' '); - - if (logObject._separator) { - separatorLength = logObject._separatorLength || this.separatorLength; - separatorType = logObject._separatorType || this.separatorType; - output = indent + Array(separatorLength - indentSize + 1).join(separatorType); - } else { - output = indent + this.parseFormatString(logObject, opts.formatString); - } - - if (opts.ansiColor) { - output = this.colorize(logObject._level, output); - } - - return output; - }, - - parseFormatString : function (logObject, formatString) { - var resultString = ''; - if (typeof formatString === 'undefined') { - formatString = this.formatString; - } +Module(Cobalt.Formatter, 'Token')({ + formatString : "{{message}}", + replaceRule : /{{(.*?)}}/g, + separatorLength : 60, + separatorType : "-", + format : function (logObject, opts){ + var indent, indentSize, + separatorLength, separatorType, + output; + indentSize = logObject._indentLevel || 0; + + indent = Array(indentSize + 1).join(' '); + + if (logObject._separator) { + separatorLength = logObject._separatorLength || this.separatorLength; + separatorType = logObject._separatorType || this.separatorType; + output = indent + Array(separatorLength - indentSize + 1).join(separatorType); + } else { + output = indent + this.parseFormatString(logObject, opts.formatString); + } - resultString = formatString.replace(this.replaceRule, function(match, paren){ - return logObject[paren] || "-"; - }); + if (opts.ansiColor) { + output = this.colorize(logObject._level, output); + } - return resultString; - }, + return output; + }, - colorize : function (level, message) { - switch(level) { - case 0: - case 1: - case 2: - case 3: - return message.red; - case 4: - return message.yellow; - case 5: - case 6: - return message.blue; - default: - return message; - } + parseFormatString : function (logObject, formatString) { + var resultString = ''; + if (typeof formatString === 'undefined') { + formatString = this.formatString; } - }); - if (typeof require === 'function') { - global.Token = Cobalt.Formatter.Token; - } else { - global.Cobalt.Formatter.Token = Cobalt.Formatter.Token; + resultString = formatString.replace(this.replaceRule, function(match, paren){ + return logObject[paren] || "-"; + }); + + return resultString; + }, + + colorize : function (level, message) { + switch(level) { + case 0: + case 1: + case 2: + case 3: + return message.red; + case 4: + return message.yellow; + case 5: + case 6: + return message.blue; + default: + return message; + } } -}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self))); +});