]>
Commit | Line | Data |
---|---|---|
db6bc3cb BB |
1 | Class(Cobalt.Logger, 'JsConsole')({ |
2 | prototype : { | |
3 | console : null, | |
4 | formatterOpts : {}, | |
bdedb5e5 | 5 | |
db6bc3cb BB |
6 | init : function (config) { |
7 | var logger = this, | |
8 | property; | |
bdedb5e5 | 9 | |
db6bc3cb BB |
10 | if (config) { |
11 | for (property in config) { | |
12 | logger[property] = config[property]; | |
bdedb5e5 | 13 | } |
db6bc3cb | 14 | } |
b03b5845 | 15 | |
db6bc3cb BB |
16 | if (!logger.console) { |
17 | logger.console = console; | |
18 | } | |
19 | }, | |
bdedb5e5 | 20 | |
db6bc3cb BB |
21 | log : function () { |
22 | var i, message = [], severity; | |
bdedb5e5 | 23 | |
db6bc3cb BB |
24 | for (i = 0; i < arguments.length; i++) { |
25 | // We're not formatting objects for now. | |
09fad45d | 26 | |
db6bc3cb BB |
27 | if (!arguments[i].__skipConsole && !arguments[i].message.__skipConsole) { |
28 | if (typeof arguments[i].message === 'object') { | |
29 | message.push(arguments[i].message); | |
30 | } else { | |
31 | message.push(this.format(arguments[i])); | |
32 | } | |
33 | if (!severity) { | |
34 | severity = arguments[i]._level | |
71a808fe BB |
35 | } |
36 | } | |
db6bc3cb | 37 | } |
71a808fe | 38 | |
db6bc3cb BB |
39 | switch (severity){ |
40 | case 0: | |
41 | case 1: | |
42 | case 2: | |
43 | case 3: | |
44 | this.console.error.apply(this.console, message); | |
45 | break; | |
46 | case 4: | |
47 | this.console.warn.apply(this.console, message); | |
48 | break; | |
49 | case 5: | |
50 | case 6: | |
51 | this.console.info.apply(this.console, message); | |
52 | break; | |
53 | case 7: | |
54 | default: | |
55 | this.console.log.apply(this.console, message); | |
56 | break; | |
bdedb5e5 | 57 | } |
db6bc3cb | 58 | }, |
bdedb5e5 | 59 | |
db6bc3cb BB |
60 | format : function (logObject) { |
61 | // Usually what you want to do here is format. Preferably using | |
62 | // someone inside Cobalt.Formatter | |
63 | if (this.formatter) { | |
64 | return this.formatter.format(logObject, this.formatterOpts); | |
65 | } | |
71a808fe | 66 | |
db6bc3cb BB |
67 | return logObject.message; |
68 | } | |
bdedb5e5 | 69 | } |
db6bc3cb | 70 | }); |