Created
June 13, 2012 21:48
-
-
Save euforic/2926685 to your computer and use it in GitHub Desktop.
Chatty Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var logger = require('lib/socket.io-client').connect({id:'MyAppName', channel:'MyAppChannel'}); | |
var window = Ti.UI.Window(); | |
window.open(); | |
var jsonTest = {'test':'testparam'}; | |
//String Example | |
logger.log('test message'); | |
//JSON Example | |
logger.log(jsonTest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Chatty logger | |
* use with Balloons.io https://github.com/gravityonmars/Balloons.IO | |
* and Titanium Socket.io https://raw.github.com/iamyellow/socket.io-client/master/dist/socket.io.js | |
*/ | |
var logger = {}; | |
var io = require('lib/socket.io'); | |
var socket = io.connect('http://localhost:3099'); | |
logger.connect = function(args){ | |
socket.emit('set nickname',{nickname:args.id ,room_id:args.channel}); | |
return logger; | |
}; | |
socket.on('new msg', function(data) { | |
if(data.nickname !== Ti.App.USERID) { Ti.UI.createAlertDialog({title:'Logger Message',message:data.nickname+':'+data.msg}).show(); } | |
}); | |
logger.log = function(data){ | |
var message = ('object' === typeof data) ? JSON.stringify(data) : data; | |
socket.emit('my msg',{msg:message}, function(){ | |
console.log('[LOGGER]:'+data); | |
}); | |
}; | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment