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