From: Ben Beltran Date: Fri, 9 Jan 2015 16:22:58 +0000 (-0600) Subject: Adds the file logger X-Git-Tag: v1.1.0~13 X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/commitdiff_plain/7f4b2a023bda5dcf9ea830b95b88bceefb331dbd?ds=sidebyside;hp=3a563eb4931fea369a87bd2f9a34d44ab81da651 Adds the file logger --- diff --git a/lib/loggers/file.js b/lib/loggers/file.js new file mode 100644 index 0000000..0512ace --- /dev/null +++ b/lib/loggers/file.js @@ -0,0 +1,49 @@ +var fs = require('fs'); + +Class(Cobalt.Logger, 'File')({ + prototype : { + file : null, + formatterOpts : {}, + + init : function (config) { + if (config) { + for (property in config) { + this[property] = config[property]; + } + } + + this._stream = fs.createWriteStream(this.file); + }, + + log : function () { + var i, message = [], severity; + + for (i = 0; i < arguments.length; i++) { + // We're not formatting objects for now. + + if (!arguments[i].__skipConsole && !arguments[i].message.__skipConsole) { + if (typeof arguments[i].message === 'object') { + message.push(arguments[i].message); + } else { + message.push(this.format(arguments[i])); + } + if (!severity) { + severity = arguments[i]._level + } + } + } + + for (i = 0; i < message.length; i++) { + this._stream.write(message[i] + '\n'); + } + }, + + format : function (logObject) { + if (this.formatter) { + return this.formatter.format(logObject, this.formatterOpts); + } + + return logObject.message; + } + } +});