aboutsummaryrefslogtreecommitdiff
path: root/lib/loggers/socket.js
blob: d9ae05577ed4a9815dc8eafaa1a9735b8c562673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function (global) {
  var Module, Class;

  // Load up dependencies
  if (typeof require === 'function') {
    var Ne = require('neon');
    Module = Ne.Module;
    Class = Ne.Class;
  } else {
    Module = global.Module;
    Class = global.Class;
  }

  var Cobalt = {};
  Module(Cobalt, 'Logger')({});

  Cobalt.Logger.Socket = Class(Cobalt.Logger, 'Socket')({
    prototype : {
      serverUrl : '/',

      init : function () {
        this._socket = io.connect(this.serverUrl);
      },

      log : function () {
        var i, messageArray = [];

        for (i = 0; i < arguments.length; i++) {
          messageArray.push(arguments[i]);
        }

        this._socket.emit('log', messageArray);
      }
    }
  });

  if (Cobalt.Logger.Socket.__objectSpy) {
    Cobalt.Logger.Socket.__objectSpy.destroy();
  }

  if (typeof require === 'function') {
    global.Socket = Cobalt.Logger.Socket;
  } else {
    global.Cobalt.Logger.Socket = Cobalt.Logger.Socket;
  }
}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));