]> git.r.bdr.sh - rbdr/cologne/blob - lib/loggers/socket.js
739c5b326852f00bc8eebc8bc5cb2c027588ac6b
[rbdr/cologne] / lib / loggers / socket.js
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.Socket = Class(Cobalt.Logger, 'Socket')({
18 prototype : {
19 serverUrl : '/',
20
21 init : function (config) {
22 var logger = this;
23 logger.socketIo = io;
24
25 if (config) {
26 for (property in config) {
27 logger[property] = config[property];
28 }
29 }
30
31 logger._socket = logger.socketIo.connect(logger.serverUrl);
32 },
33
34 log : function () {
35 var i, messageArray = [];
36
37 for (i = 0; i < arguments.length; i++) {
38 messageArray.push(arguments[i]);
39 }
40
41 this._socket.emit('log', messageArray);
42 }
43 }
44 });
45
46 if (Cobalt.Logger.Socket.__objectSpy) {
47 Cobalt.Logger.Socket.__objectSpy.destroy();
48 }
49
50 if (typeof require === 'function') {
51 global.Socket = Cobalt.Logger.Socket;
52 } else {
53 global.Cobalt.Logger.Socket = Cobalt.Logger.Socket;
54 }
55 }(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));