-
-
Save skypanther/1650413 to your computer and use it in GitHub Desktop.
console.log - appcelerator
This file contains hidden or 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
/* | |
Custom logger | |
// usage | |
var console = require('/logger'); | |
console.log({sdf:"df"}, [1,3,5,6], "sdfsdf"); | |
*/ | |
exports.log = function() { | |
if(Ti.App.Properties.getBool('production')==false) { | |
// set key in tiapp.xml for this | |
// <property name="production" type="bool">true</property> | |
// so in production mode, don't actually do any logging | |
var log = ''; | |
for(var i = 0, len = arguments.length; i < len; i++){ | |
switch(typeof(arguments[i])) { | |
case 'string': | |
case 'number': | |
log += ' '+arguments[i]; | |
break; | |
case 'boolean': | |
log += ' '+ (arguments[i]) ? 'true' : 'false'; | |
break; | |
case 'object': | |
case 'array': | |
log += ' '+JSON.stringify(arguments[i]); | |
break; | |
case 'undefined': | |
log += ' undefined'; | |
break; | |
default: | |
log += ' null'; | |
} | |
} | |
Ti.API.info(log); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment