]> git.r.bdr.sh - rbdr/cologne/blame - lib/loggers/file.js
Makes file logger append by default
[rbdr/cologne] / lib / loggers / file.js
CommitLineData
7f4b2a02
BB
1var fs = require('fs');
2
3Class(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
54a5290b 15 this._stream = fs.createWriteStream(this.file, {flags: 'a'});
7f4b2a02
BB
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) {
de7f6029 25 message.push(this.format(arguments[i]));
7f4b2a02
BB
26 if (!severity) {
27 severity = arguments[i]._level
28 }
29 }
30 }
31
32 for (i = 0; i < message.length; i++) {
33 this._stream.write(message[i] + '\n');
34 }
35 },
36
37 format : function (logObject) {
38 if (this.formatter) {
de7f6029
BB
39 if (typeof logObject.message === 'object') {
40 return logObject.message;
41 }
7f4b2a02
BB
42 return this.formatter.format(logObject, this.formatterOpts);
43 }
44
de7f6029 45 return Cobalt.stringify(logObject);
7f4b2a02
BB
46 }
47 }
48});