Is your code packed with Ti.API.
and console.
calls? Good! They are really useful to inspect and debug your app. But once in production only error-level messages end up in the console for iOS, whereas Android only filters debug-calls out. So for messages you don’t want to show in production use Ti.API.debug
and for messages that should use Ti.API.error
. Be aware of this in particular when logging sensitive information.
An alternative: ti-stealth 
I just pushed a small NodeJS CLI, CommonJS module and example alloy.jmk
to help you deal with stripping log calls from production: ti-stealth.
Drop the included example alloy.jmk
in your Alloy app’s app
folder or merge it with your existing file’s post:compile
hook:
task("post:compile", function(event, logger) { if (event.alloyConfig.deployType === 'production') { require('ti-stealth').enable(event.dir.resources, { notLevels: 'error' }); } });
After Alloy has compiled to Resources
, Stealth will replace all non-error log calls like:
// before: Ti.API.info('hello'); // after: (function(){/*Ti.API.info*/})('hello');
You can safely run the Stealth CLI ($ ti-stealth enable <path>
) on classic Titanium projects as well, since the original logging method is preserved in comments can be restored using $ ti-stealth restore <path>
.
Comments
Richard Lustemberg
Cool stuff, Fokke!
developer82
Why don’t just comment it? why do you turn it to a self executing function that does nothing? seems like a little overhead…
Fokke Zandbergen Post author
@developer82 It has been a while ago but if remember correctly it had something to do with cases where the surrounding code was relying on having a function to return or call.