X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/bdedb5e54032363de8afa322fadae0e2cb2132d0..7f4b2a023bda5dcf9ea830b95b88bceefb331dbd:/lib/loggers/socket.js diff --git a/lib/loggers/socket.js b/lib/loggers/socket.js index 8d0ff55..7066274 100644 --- a/lib/loggers/socket.js +++ b/lib/loggers/socket.js @@ -1,36 +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'); +} - var Cobalt = {}; - Module(Cobalt, 'Logger')({}); +Class(Cobalt.Logger, 'Socket')({ + prototype : { + serverUrl : '/', - Cobalt.Logger.Socket = Class(Cobalt.Logger, 'Socket')({ - prototype : { - serverUrl : '/', + init : function (config) { + var logger = this; - init : function () { - this._socket = io.connect(this.serverUrl); - }, + if (config) { + for (property in config) { + logger[property] = config[property]; + } + } - log : function (logObject) { - this._socket.emit('log', logObject); + if (!logger.socketIo) { + logger.socketIo = ioClient; } - } - }); - if (typeof require === 'function') { - global.Socket = Cobalt.Logger.Socket; - } else { - global.Cobalt.Logger.Socket = Cobalt.Logger.Socket; + logger._socket = logger.socketIo.connect(logger.serverUrl); + }, + + log : function () { + var i, messageArray = []; + + for (i = 0; i < arguments.length; i++) { + messageArray.push(arguments[i]); + } + + if (this._socket) { + this._socket.emit('log', messageArray); + } + } } -}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self))); +});