]> git.r.bdr.sh - rbdr/cologne/blame_incremental - lib/loggers/console.js
Bump version
[rbdr/cologne] / lib / loggers / console.js
... / ...
CommitLineData
1(function (global) {
2 var Module, Class;
3
4 // Load up dependencies
5 if (typeof require === 'function') {
6 var Ne = require('neon');
7 Module = Ne.Module;
8 Class = Ne.Class;
9 } else {
10 Module = global.Module;
11 Class = global.Class;
12 }
13
14 var Cobalt = {};
15 Module(Cobalt, 'Logger')({});
16
17 Cobalt.Logger.JsConsole = Class(Cobalt.Logger, 'JsConsole')({
18 prototype : {
19 console : null,
20 formatterOpts : {},
21
22 init : function (config) {
23 var logger = this,
24 property;
25
26 if (config) {
27 for (property in config) {
28 logger[property] = config[property];
29 }
30 }
31
32 if (!logger.console) {
33 logger.console = console;
34 }
35 },
36
37 log : function () {
38 var i, message = [], severity;
39
40 for (i = 0; i < arguments.length; i++) {
41 // We're not formatting objects for now.
42
43 if (typeof arguments[i].message === 'object') {
44 message.push(arguments[i].message);
45 } else {
46 message.push(this.format(arguments[i]));
47 }
48 if (!severity) {
49 severity = arguments[i]._level
50 }
51 }
52
53 switch (severity){
54 case 0:
55 case 1:
56 case 2:
57 case 3:
58 this.console.error.apply(this.console, message);
59 break;
60 case 4:
61 this.console.warn.apply(this.console, message);
62 break;
63 case 5:
64 case 6:
65 this.console.info.apply(this.console, message);
66 break;
67 case 7:
68 default:
69 this.console.log.apply(this.console, message);
70 break;
71 }
72 },
73
74 format : function (logObject) {
75 // Usually what you want to do here is format. Preferably using
76 // someone inside Cobalt.Formatter
77 if (this.formatter) {
78 return this.formatter.format(logObject, this.formatterOpts);
79 }
80
81 return logObject.message;
82 }
83 }
84 });
85
86 if (Cobalt.Logger.JsConsole.__objectSpy) {
87 Cobalt.Logger.JsConsole.__objectSpy.destroy();
88 }
89
90 if (typeof require === 'function') {
91 global.JsConsole = Cobalt.Logger.JsConsole;
92 } else {
93 global.Cobalt.Logger.JsConsole = Cobalt.Logger.JsConsole;
94 }
95}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));