]> git.r.bdr.sh - rbdr/cologne/blame_incremental - lib/loggers/socket.js
Properly handle logging null.
[rbdr/cologne] / lib / loggers / socket.js
... / ...
CommitLineData
1(function (global) {
2 var Module, Class;
3
4 // Load up dependencies
5 if (typeof require === 'function') {
6 var Ne = require('neon');
7 var ioClient = require('socket.io-client');
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
22 init : function (config) {
23 var logger = this;
24
25 if (config) {
26 for (property in config) {
27 logger[property] = config[property];
28 }
29 }
30
31 if (!logger.socketIo) {
32 logger.socketIo = ioClient;
33 }
34
35 logger._socket = logger.socketIo.connect(logger.serverUrl);
36 },
37
38 log : function () {
39 var i, messageArray = [];
40
41 for (i = 0; i < arguments.length; i++) {
42 messageArray.push(arguments[i]);
43 }
44
45 if (this._socket) {
46 this._socket.emit('log', messageArray);
47 }
48 }
49 }
50 });
51
52 if (Cobalt.Logger.Socket.__objectSpy) {
53 Cobalt.Logger.Socket.__objectSpy.destroy();
54 }
55
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)));