]>
Commit | Line | Data |
---|---|---|
bdedb5e5 BB |
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 : { | |
71a808fe | 19 | console : null, |
bdedb5e5 BB |
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 | } | |
b03b5845 BB |
31 | |
32 | if (!logger.console) { | |
ce8edf20 | 33 | logger.console = console; |
b03b5845 | 34 | } |
bdedb5e5 BB |
35 | }, |
36 | ||
71a808fe | 37 | log : function () { |
09fad45d | 38 | var i, message = [], severity; |
bdedb5e5 | 39 | |
71a808fe | 40 | for (i = 0; i < arguments.length; i++) { |
09fad45d BB |
41 | // We're not formatting objects for now. |
42 | ||
c315b8c3 BB |
43 | if (!arguments[i].__skipConsole && !arguments[i].message.__skipConsole) { |
44 | if (typeof arguments[i].message === 'object') { | |
45 | message.push(arguments[i].message); | |
46 | } else { | |
47 | message.push(this.format(arguments[i])); | |
48 | } | |
49 | if (!severity) { | |
50 | severity = arguments[i]._level | |
51 | } | |
71a808fe BB |
52 | } |
53 | } | |
54 | ||
71a808fe | 55 | switch (severity){ |
bdedb5e5 BB |
56 | case 0: |
57 | case 1: | |
58 | case 2: | |
59 | case 3: | |
09fad45d | 60 | this.console.error.apply(this.console, message); |
bdedb5e5 BB |
61 | break; |
62 | case 4: | |
09fad45d | 63 | this.console.warn.apply(this.console, message); |
bdedb5e5 BB |
64 | break; |
65 | case 5: | |
66 | case 6: | |
09fad45d | 67 | this.console.info.apply(this.console, message); |
bdedb5e5 BB |
68 | break; |
69 | case 7: | |
70 | default: | |
09fad45d | 71 | this.console.log.apply(this.console, message); |
bdedb5e5 BB |
72 | break; |
73 | } | |
74 | }, | |
75 | ||
76 | format : function (logObject) { | |
77 | // Usually what you want to do here is format. Preferably using | |
78 | // someone inside Cobalt.Formatter | |
79 | if (this.formatter) { | |
80 | return this.formatter.format(logObject, this.formatterOpts); | |
81 | } | |
82 | ||
09fad45d | 83 | return logObject.message; |
bdedb5e5 BB |
84 | } |
85 | } | |
86 | }); | |
87 | ||
71a808fe BB |
88 | if (Cobalt.Logger.JsConsole.__objectSpy) { |
89 | Cobalt.Logger.JsConsole.__objectSpy.destroy(); | |
90 | } | |
91 | ||
bdedb5e5 BB |
92 | if (typeof require === 'function') { |
93 | global.JsConsole = Cobalt.Logger.JsConsole; | |
94 | } else { | |
95 | global.Cobalt.Logger.JsConsole = Cobalt.Logger.JsConsole; | |
96 | } | |
97 | }(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self))); |