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