Skip to content

Instantly share code, notes, and snippets.

@skypanther
Forked from pec1985/app.js
Created January 21, 2012 00:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skypanther/1650413 to your computer and use it in GitHub Desktop.
Save skypanther/1650413 to your computer and use it in GitHub Desktop.
console.log - appcelerator
/*
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