]>
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 | ||
43 | if (typeof arguments[i].message === 'object') { | |
44 | message.push(arguments[i].message); | |
45 | } else { | |
46 | message.push(this.format(arguments[i])); | |
47 | } | |
71a808fe BB |
48 | if (!severity) { |
49 | severity = arguments[i]._level | |
50 | } | |
51 | } | |
52 | ||
71a808fe | 53 | switch (severity){ |
bdedb5e5 BB |
54 | case 0: |
55 | case 1: | |
56 | case 2: | |
57 | case 3: | |
09fad45d | 58 | this.console.error.apply(this.console, message); |
bdedb5e5 BB |
59 | break; |
60 | case 4: | |
09fad45d | 61 | this.console.warn.apply(this.console, message); |
bdedb5e5 BB |
62 | break; |
63 | case 5: | |
64 | case 6: | |
09fad45d | 65 | this.console.info.apply(this.console, message); |
bdedb5e5 BB |
66 | break; |
67 | case 7: | |
68 | default: | |
09fad45d | 69 | this.console.log.apply(this.console, message); |
bdedb5e5 BB |
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 | ||
09fad45d | 81 | return logObject.message; |
bdedb5e5 BB |
82 | } |
83 | } | |
84 | }); | |
85 | ||
71a808fe BB |
86 | if (Cobalt.Logger.JsConsole.__objectSpy) { |
87 | Cobalt.Logger.JsConsole.__objectSpy.destroy(); | |
88 | } | |
89 | ||
bdedb5e5 BB |
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))); |