]>
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'); | |
8da0b42e | 7 | var ioClient = require('socket.io-client'); |
bdedb5e5 BB |
8 | Module = Ne.Module; |
9 | Class = Ne.Class; | |
10 | } else { | |
11 | Module = global.Module; | |
12 | Class = global.Class; | |
13 | } | |
14 | ||
15 | var Cobalt = {}; | |
16 | Module(Cobalt, 'Logger')({}); | |
17 | ||
18 | Cobalt.Logger.Socket = Class(Cobalt.Logger, 'Socket')({ | |
19 | prototype : { | |
20 | serverUrl : '/', | |
21 | ||
c315b8c3 BB |
22 | init : function (config) { |
23 | var logger = this; | |
b39688c9 | 24 | |
c315b8c3 BB |
25 | if (config) { |
26 | for (property in config) { | |
27 | logger[property] = config[property]; | |
28 | } | |
29 | } | |
30 | ||
8da0b42e BB |
31 | if (!logger.socketIo) { |
32 | logger.socketIo = ioClient; | |
b39688c9 | 33 | } |
8da0b42e BB |
34 | |
35 | logger._socket = logger.socketIo.connect(logger.serverUrl); | |
bdedb5e5 BB |
36 | }, |
37 | ||
71a808fe BB |
38 | log : function () { |
39 | var i, messageArray = []; | |
40 | ||
41 | for (i = 0; i < arguments.length; i++) { | |
42 | messageArray.push(arguments[i]); | |
43 | } | |
44 | ||
b39688c9 BB |
45 | if (this._socket) { |
46 | this._socket.emit('log', messageArray); | |
47 | } | |
bdedb5e5 BB |
48 | } |
49 | } | |
50 | }); | |
51 | ||
71a808fe BB |
52 | if (Cobalt.Logger.Socket.__objectSpy) { |
53 | Cobalt.Logger.Socket.__objectSpy.destroy(); | |
54 | } | |
55 | ||
bdedb5e5 BB |
56 | if (typeof require === 'function') { |
57 | global.Socket = Cobalt.Logger.Socket; | |
58 | } else { | |
59 | global.Cobalt.Logger.Socket = Cobalt.Logger.Socket; | |
60 | } | |
61 | }(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self))); |