[ALOY-723] Alloy: Remove log unimportant log calls in production
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Medium |
| Status | Closed |
| Resolution | Won't Fix |
| Resolution Date | 2014-01-20T20:37:52.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | 2014 Sprint 02 |
| Components | n/a |
| Labels | alloy, compile, compiler, log, logging, production |
| Reporter | Carter Lathrop |
| Assignee | Tim Poulsen |
| Created | 2013-06-26T07:47:35.000+0000 |
| Updated | 2014-01-28T23:19:49.000+0000 |
Description
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
Investigating, I think this is already done by the platform.
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:
For non-Alloy projects, add a custom property to tiapp.xml, and check for it, like this:/* Use: 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; Ti.API.info(str); };// 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; Ti.API.info(str); };I'm marking this as "won't fix" because it's partially handled by the underlying platform and suitable workarounds are available.
[~skypanther], you're worse then Tony ;)
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?
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.