Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-8424

Ti API: Define cross platform logging API

    Details

    • Type: Story
    • Status: Closed
    • Priority: High
    • Resolution: Invalid
    • Affects Version/s: Release 2.0.0, Release 3.0.2
    • Fix Version/s: None
    • Component/s: TiAPI
    • Labels:

      Description

      Currently, Ti.API defines several redundant logging methods. These include:

      Ti.API.notice – duplicates Ti.API.info but with a less-obvious name
      Ti.API.critical, Ti.API.fatal – duplicate Ti.API.error

      We need a larger discussion to lay out how logging should work and look like across all platforms.

      Sample Code:

      /* console */
       
      console.log();
      console.log('console.log');
      console.log(['console.log.0', 'console.log.1']);
       
      console.debug();
      console.debug('console.debug');
      console.debug(['console.debug.0', 'console.debug.1']);
       
      console.info();
      console.info('console.info');
      console.info(['console.info.0', 'console.info.1']);
       
      console.warn();
      console.warn('console.warn');
      console.warn(['console.warn.0', 'console.warn.1']);
       
      console.error();
      console.error('console.error');
      console.error(['console.error.0', 'console.error.1']);
       
      /* Ti.API */
       
      Ti.API.trace();
      Ti.API.trace('Ti.API.trace');
      Ti.API.trace(['Ti.API.trace.0', 'Ti.API.trace.1']);
       
      Ti.API.debug();
      Ti.API.debug('Ti.API.debug');
      Ti.API.debug(['Ti.API.debug.0', 'Ti.API.debug.1']);
       
      Ti.API.info();
      Ti.API.info('Ti.API.info');
      Ti.API.info(['Ti.API.info.0', 'Ti.API.info.1']);
       
      Ti.API.warn();
      Ti.API.warn('Ti.API.warn');
      Ti.API.warn(['Ti.API.warn.0', 'Ti.API.warn.1']);
       
      Ti.API.error();
      Ti.API.error('Ti.API.error');
      Ti.API.error(['Ti.API.error.0', 'Ti.API.error.1']);
       
      /* Ti.API.log */
       
      Ti.API.log();
       
      Ti.API.log('trace');
      Ti.API.log('trace', 'Ti.API.log.trace');
      Ti.API.log('trace', ['Ti.API.trace.0', 'Ti.API.trace.1']);
       
      Ti.API.log('debug');
      Ti.API.log('debug', 'Ti.API.log.debug');
      Ti.API.log('debug', ['Ti.API.debug.0', 'Ti.API.debug.1']);
       
      Ti.API.log('info');
      Ti.API.log('info', 'Ti.API.log.info');
      Ti.API.log('info', ['Ti.API.info.0', 'Ti.API.info.1']);
       
      Ti.API.log('warn');
      Ti.API.log('warn', 'Ti.API.log.warn');
      Ti.API.log('warn', ['Ti.API.warn.0', 'Ti.API.warn.1']);
       
      Ti.API.log('error');
      Ti.API.log('error', 'Ti.API.log.error');
      Ti.API.log('error', ['Ti.API.error.0', 'Ti.API.error.1']);
       
      Ti.API.log('log');
      Ti.API.log('log', 'Ti.API.log.log');
      Ti.API.log('log', ['Ti.API.log.0', 'Ti.API.log.1']);
       
      /* Ti.iOS.API */
       
      if(Ti.Platform.osname == 'iphone' || Ti.Platform.osname == 'ipad')
      {
      	Ti.API.timestamp();
      	Ti.API.timestamp('Ti.API.timestamp');
      	Ti.API.timestamp(['Ti.API.timestamp.0', 'Ti.API.timestamp.1']);
      	
      	Ti.API.log('timestamp');
      	Ti.API.log('timestamp', 'Ti.API.log.timestamp');
      	Ti.API.log('timestamp', ['Ti.API.timestamp.0', 'Ti.API.timestamp.1']);
      }
      

      Sample Test App with Buttons:

      var win = Ti.UI.createWindow({
      	backgroundColor : 'blue',
      	layout : 'vertical'
      });
       
      var con = Ti.UI.createButton({title:'console', height : '20%', width : '80%'});
      var api = Ti.UI.createButton({title:'api', height : '20%', width : '80%'});
      var log = Ti.UI.createButton({title:'log', height : '20%', width : '80%'});
      var all = Ti.UI.createButton({title:'all', height : '20%', width : '80%'});
      var array = Ti.UI.createButton({title:'array', height : '20%', width : '80%'});
       
      con.addEventListener('click', function(){
      	console.trace('console.trace');
      	console.debug('console.debug');
      	console.info('console.info');
      	console.warn('console.warn');
      	console.error('console.error');
      });
       
      api.addEventListener('click', function(){
      	Ti.API.trace('Ti.API.trace');
      	Ti.API.debug('Ti.API.debug');
      	Ti.API.info('Ti.API.info');
      	Ti.API.warn('Ti.API.warn');
      	Ti.API.error('Ti.API.error');
      });
       
      log.addEventListener('click', function(){
      	Ti.API.log('trace', 'Ti.API.log(trace)');
      	Ti.API.log('debug', 'Ti.API.log(debug)');
      	Ti.API.log('info', 'Ti.API.log(info)');
      	Ti.API.log('warn', 'Ti.API.log(warn)');
      	Ti.API.log('error', 'Ti.API.log(error)');
      	Ti.API.log('custom', 'Ti.API.log(custom)');
      	Ti.API.log('custom', ['Ti.API.log(custom, [])', 'arg1', 'arg2']);
      });
       
      all.addEventListener('click', function(){
      	con.fireEvent('click');
      	api.fireEvent('click');
      	log.fireEvent('click');
      	
      	switch(Ti.Platform.osname)
      	{
      		case 'iphone':
      		case 'ipad': Ti.API.timestamp();
      	}
      });
       
      array.addEventListener('click', function(){
      	var a = ['long string', 0, 'pig', 'goat', 'BIGCAPS', 999, '000', 'TWO GO'];
      	
      	console.info(a);
      	Ti.API.info(a);
      	Ti.API.log('custom', a);
      	
      	switch(Ti.Platform.osname)
      	{
      		case 'iphone':
      		case 'ipad': Ti.API.timestamp(a);
      	}
      });
       
      win.add(con);
      win.add(api);
      win.add(log);
      win.add(all);
      win.add(array);
       
      win.open();
      

        Attachments

          Issue Links

          1.
          iOS: API.log with timestamp arg fails to log timestamp Sub-task Closed Ingo Muschenetz
           
          2.
          iOS: Ti.API.log: function calls with one arg (log level) do not print as the correct log level Sub-task Closed Ingo Muschenetz
           
          3.
          Android: Ti.API.log: function calls with one arg (log level) do not print as the correct log level, and have some format problems Sub-task Closed Ingo Muschenetz
           
          4.
          Android: Ti.API: console logging calls with no arg do not print at all Sub-task Open Unassigned
           
          5.
          iOS: Ti.API: some console logging calls with array args do not print array to console Sub-task Closed Ingo Muschenetz
           
          6.
          iOS: console logging functions with no args print as null Sub-task Open Unassigned
           
          7.
          MobileWeb: console: js logging functions do not log with any log level Sub-task Closed Chris Barber
           
          8.
          MobileWeb: console: js logging functions with no arg do not log to console at all Sub-task Closed Chris Barber
           
          9.
          MobileWeb: Ti.API.log INFO level messages do not display as correct type Sub-task Closed Bryan Hughes
           
          10.
          Android: API Debug - Internal Titanium code is exposed through Ti.API.debug() method Sub-task Closed Ingo Muschenetz
           
          11.
          MobileWeb: Add trace(), notice(), fatal(), and critical() to Ti.API Sub-task Closed Chris Barber
           
          12.
          iOS: console logging with array arg displays on multiple lines, should be one line Sub-task Open Unassigned
           
          13.
          CLI: iOS Console Output missing first arg of some arrays Sub-task Closed Chris Barber
           
          14.
          CLI: iOS Console output prints out of order Sub-task Closed Chris Barber
           
          15.
          SDK Console: log messages are incorrect capitalization Sub-task Closed Eric Merriman
           
          16.
          iOS: Device Debugger: Titanium SDK log messages print out of order Sub-task Closed Eric Merriman
           
          17.
          iOS: Titanium SDK logs all print at warning level in Xcode console Sub-task Open Unassigned
           
          18.
          CLI: colors, lines, and messages ill-formatted with CLI enabled Sub-task Closed Chris Barber
           
          19.
          MobileWeb: Strip console.* and Ti.API.* log calls during production builds Sub-task Closed Chris Barber
           

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                aevans Arthur Evans
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-12760
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration