From: Ben Beltran Date: Fri, 9 Jan 2015 16:22:58 +0000 (-0600) Subject: Adds the file logger X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/commitdiff_plain/204d9a1e0a3dd36bc3f91800ab82e9075610b94e 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; + } + } +});