]> git.r.bdr.sh - rbdr/cologne/blob - lib/loggers/file.js
0512ace110910559389916b3a63f870f0341edf3
[rbdr/cologne] / lib / loggers / file.js
1 var fs = require('fs');
2
3 Class(Cobalt.Logger, 'File')({
4 prototype : {
5 file : null,
6 formatterOpts : {},
7
8 init : function (config) {
9 if (config) {
10 for (property in config) {
11 this[property] = config[property];
12 }
13 }
14
15 this._stream = fs.createWriteStream(this.file);
16 },
17
18 log : function () {
19 var i, message = [], severity;
20
21 for (i = 0; i < arguments.length; i++) {
22 // We're not formatting objects for now.
23
24 if (!arguments[i].__skipConsole && !arguments[i].message.__skipConsole) {
25 if (typeof arguments[i].message === 'object') {
26 message.push(arguments[i].message);
27 } else {
28 message.push(this.format(arguments[i]));
29 }
30 if (!severity) {
31 severity = arguments[i]._level
32 }
33 }
34 }
35
36 for (i = 0; i < message.length; i++) {
37 this._stream.write(message[i] + '\n');
38 }
39 },
40
41 format : function (logObject) {
42 if (this.formatter) {
43 return this.formatter.format(logObject, this.formatterOpts);
44 }
45
46 return logObject.message;
47 }
48 }
49 });