]>
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 BB |
37 | log : function () { |
38 | var i, messageArray = [], message, severity; | |
bdedb5e5 | 39 | |
71a808fe BB |
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(' '); | |
bdedb5e5 | 48 | |
71a808fe | 49 | switch (severity){ |
bdedb5e5 BB |
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 | ||
71a808fe BB |
82 | if (Cobalt.Logger.JsConsole.__objectSpy) { |
83 | Cobalt.Logger.JsConsole.__objectSpy.destroy(); | |
84 | } | |
85 | ||
bdedb5e5 BB |
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))); |