]> git.r.bdr.sh - rbdr/cologne/blob - lib/loggers/console.js
465a436a5e968114e3f76a502dfdbbcf52f3d968
[rbdr/cologne] / lib / loggers / console.js
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 = global.console;
34 }
35 },
36
37 log : function () {
38 var i, messageArray = [], message, severity;
39
40 for (i = 0; i < arguments.length; i++) {
41 messageArray.push(this.format(arguments[i]));
42 if (!severity) {
43 severity = arguments[i]._level
44 }
45 }
46
47 message = messageArray.join(' ');
48
49 switch (severity){
50 case 0:
51 case 1:
52 case 2:
53 case 3:
54 this.console.error(message);
55 break;
56 case 4:
57 this.console.warn(message);
58 break;
59 case 5:
60 case 6:
61 this.console.info(message);
62 break;
63 case 7:
64 default:
65 this.console.log(message);
66 break;
67 }
68 },
69
70 format : function (logObject) {
71 // Usually what you want to do here is format. Preferably using
72 // someone inside Cobalt.Formatter
73 if (this.formatter) {
74 return this.formatter.format(logObject, this.formatterOpts);
75 }
76
77 return logObject;
78 }
79 }
80 });
81
82 if (Cobalt.Logger.JsConsole.__objectSpy) {
83 Cobalt.Logger.JsConsole.__objectSpy.destroy();
84 }
85
86 if (typeof require === 'function') {
87 global.JsConsole = Cobalt.Logger.JsConsole;
88 } else {
89 global.Cobalt.Logger.JsConsole = Cobalt.Logger.JsConsole;
90 }
91 }(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));