X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/71a808fe142f1c10f9e7de90877fb6e4ffc70158..97a7ece70e89b973468b62e1775a33762a37258e:/lib/loggers/socket.js diff --git a/lib/loggers/socket.js b/lib/loggers/socket.js index d9ae055..7066274 100644 --- a/lib/loggers/socket.js +++ b/lib/loggers/socket.js @@ -1,46 +1,37 @@ -(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; - } +if (typeof require === 'function') { + var ioClient = require('socket.io-client'); +} + +Class(Cobalt.Logger, 'Socket')({ + prototype : { + serverUrl : '/', - var Cobalt = {}; - Module(Cobalt, 'Logger')({}); + init : function (config) { + var logger = this; - Cobalt.Logger.Socket = Class(Cobalt.Logger, 'Socket')({ - prototype : { - serverUrl : '/', + if (config) { + for (property in config) { + logger[property] = config[property]; + } + } - init : function () { - this._socket = io.connect(this.serverUrl); - }, + if (!logger.socketIo) { + logger.socketIo = ioClient; + } - log : function () { - var i, messageArray = []; + logger._socket = logger.socketIo.connect(logger.serverUrl); + }, - for (i = 0; i < arguments.length; i++) { - messageArray.push(arguments[i]); - } + log : function () { + var i, messageArray = []; + for (i = 0; i < arguments.length; i++) { + messageArray.push(arguments[i]); + } + + if (this._socket) { 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))); +});