[ALOY-723] Alloy: Remove log unimportant log calls in production

GitHub Issuen/a
ResolutionWon't Fix
Resolution Date2014-01-20T20:37:52.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 02
Labelsalloy, compile, compiler, log, logging, production
ReporterCarter Lathrop
AssigneeTim Poulsen


The compiler should remove Titanium.API.log (and console.log) calls from the code that are not relevant in production environments, being log and debug. An implementation for this is already provided here: https://gist.github.com/tsteur/5745279


  1. Tim Poulsen 2014-01-20 Investigating, I think this is already done by the platform.
  2. Tim Poulsen 2014-01-20 At the platform level, debug() messages are apparently not output though the other levels are output. Platform references: * iOS: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/APIModule.m * Android: https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/java/org/appcelerator/kroll/common/Log.java If your concern is crossing the bridge, you can write a simple wrapper for the Ti.API.info() like the following:
            var log = require('logger');
            log.info('Logged, except in a production build');
       // put in app/lib/logger.js
       exports.info = function(str) {
           if(ENV_PRODUCTION) return;
    For non-Alloy projects, add a custom property to tiapp.xml, and check for it, like this:
       // in tiapp.xml, add:
       <property name="production" type="bool">false</property>
       // in your logger.js
       exports.info = function(str) {
           if(Ti.App.Properties.getBool('production', false)===true) return;
  3. Tim Poulsen 2014-01-20 I'm marking this as "won't fix" because it's partially handled by the underlying platform and suitable workarounds are available.
  4. Fokke Zandbergen 2014-01-20 [~skypanther], you're worse then Tony ;)
  5. Matthew Tondreau 2014-01-22 Looking at: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/APIModule.m#L53 https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/v8/src/native/modules/APIModule.cpp#L169 Is it correct to say in production (non-debug) iphone only logs error-level, where with android only debug-level is *not* displayed?
  6. Tim Poulsen 2014-01-22 Yes, Matthew, that's how the API level handles it. I've opened a docs ticket to document the behavior since it doesn't seem to be covered anywhere right now.

JSON Source