aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2015-01-09 10:22:58 -0600
committerBen Beltran <ben@nsovocal.com>2015-01-09 10:22:58 -0600
commit204d9a1e0a3dd36bc3f91800ab82e9075610b94e (patch)
treece4c1aeea5ace391f842de7ab1d011c722718f7c /lib
parent57c44bcddcbdb267bcf39550d9b8b19ebfdc4a51 (diff)
Adds the file logger
Diffstat (limited to 'lib')
-rw-r--r--lib/loggers/file.js49
1 files changed, 49 insertions, 0 deletions
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;
+ }
+ }
+});