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