Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26572] TiAPI: Extend global console API to be more Node-compatible

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-03-06T16:35:54.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.1.0
ComponentsTiAPI
Labelsn/a
ReporterChristopher Williams
AssigneeChristopher Williams
Created2018-11-16T16:24:13.000+0000
Updated2020-03-31T17:11:05.000+0000

Description

Our current console global object has the most common methods, but is missing some easy ones to target. - assert - count - countReset - trace Some other methods may be useful to simply implement as no-ops (like #clear()) https://nodejs.org/api/console.html Tony Lukasavage has a JS impl to add trace/assert/dir here: https://github.com/tonylukasavage/ti-console/blob/master/src/ti-console.js

Comments

  1. Christopher Williams 2018-12-19

    I think given that on Android and Windows we already have JS code to implement some of console, it'd be fairly simple to move this into the common area and expand upon it. https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/js/console.js https://github.com/appcelerator/titanium_mobile_windows/blob/master/Source/TitaniumKit/src/TiModule.cpp#L493-L531
  2. Ewan Harris 2019-01-02

    [~cwilliams] I started to look into this, I'm not sure whether we would consider it a breaking change? iOS defines a [TiConsole](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/TitaniumKit/TitaniumKit/Sources/API/TiConsole.m), which is then added to the globals [here](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/TitaniumKit/TitaniumKit/Sources/API/KrollBridge.m#L557-L560). Is TitaniumKit itself seen as a public API, or is just Titanium SDK our public API. As I understand, if it's the former then this should be a breaking change
  3. Christopher Williams 2019-07-29

    The original goal from Matt Langston back in the early days of TitaniumKit/HAL was to make that the core foundation of all the platforms, but no one has the appetite to throw away our core stuff on iOS and replace it - let alone consider how we'd hook up JSC for Android. I'd only consider the SDK as our public API. I don't think this should be a breaking change, basically we just move any methods we can into the common JS code we ship in the SDK and leave say the base methods (like #log()) done natively. If we want to be extra safe, we can sniff if the console object already has an implementation for any given method and not override it.
  4. Christopher Williams 2020-01-09

    WIP PR: https://github.com/appcelerator/titanium_mobile/pull/11425
  5. Christopher Williams 2020-01-09

    https://github.com/appcelerator/titanium_mobile/pull/11425
  6. Christopher Williams 2020-03-06

    Merged to master for 9.1.0 target
  7. Samir Mohammed 2020-03-31

    FR Passed: Tested by looking at the results of the Unit tests in Jenkins and a quick titanium application outlining various features.
       var window = Titanium.UI.createWindow({
          backgroundColor:'white'
       });
       
       console.log('*********************************************************************************************')
       console.log('Log')
       console.info('info')
       console.error('error')
       console.warn('warm')
       console.log('*********************************************************************************************')
       
       console.log('*********************************************************************************************')
       console.time('mytimer'); // Start timer
       console.timeLog('mytimer'); // Log time taken so far
       console.timeLog('mytimer', 'with', 'some', 'extra', 'info'); // Log time taken with extra logging
       console.timeLog('mytimer', [ 'a', 'b', 'c' ], { objects: true }); // Should handle Arrays and Objects
       console.timeEnd('mytimer');
       console.log('*********************************************************************************************')
       
       var buttonClear = Titanium.UI.createButton({
       title: 'Clear',
       top: 10,
       });
       buttonClear.addEventListener('click',function(e)
       {
         console.clear()
         console.log('Clear should be a function, does not do anything')
       });
       
       var buttonCount = Titanium.UI.createButton({
       title: 'Count',
       top: 30,
       });
       buttonCount.addEventListener('click',function(e)
       {
         console.count()
       });
       
       var buttonClearCount = Titanium.UI.createButton({
       title: 'Clear Count',
       top: 50,
       });
       buttonClearCount.addEventListener('click',function(e)
       {
         console.countReset()
       });
       
       var buttonGroup = Titanium.UI.createButton({
       title: 'Group',
       top: 70,
       });
       buttonGroup.addEventListener('click',function(e)
       {
         const logs = [];
         			const fakeTiAPI = {
         				warn: msg => {
         					logs.push([WARN]${msg});
         				},
         				debug: msg => {
         					logs.push([DEBUG]${msg});
         				},
         				info: msg => {
         					logs.push([INFO]${msg});
         				},
         				error: msg => {
         					logs.push([ERROR]${msg});
         				},
         				apiName: 'Ti.API',
         			};
               console.group('mylabel');
         			console.log('this should be indented');
         			console.groupEnd();
         			console.group();
         			console.group('something');
         			console.warn('this should be indented twice'); // FIXME: Hijack warn too!
         			console.groupEnd();
         			console.log('this should be indented');
         			console.groupEnd();
         			console.log('this should NOT be indented');
       });
       
       var buttonDir = Titanium.UI.createButton({
       title: 'Dir',
       top: 90,
       });
       buttonDir.addEventListener('click',function(e)
       {
         console.dir(1);
         console.dir('1');
         console.dir(null);
         console.dir(undefined);
         console.dir({ 1: [ 2 ] });
       });
       
       window.open({fullscreen:true});
       window.add(buttonClear)
       window.add(buttonCount)
       window.add(buttonClearCount)
       window.add(buttonGroup)
       window.add(buttonDir)
       
       
    *Test environment*
       MacOS Catalina: 10.15.1 beta
       Xcode: 11.3
       Java Version: 1.8.0_131
       Android NDK: 21.1.6273396-beta2
       Node.js: 10.16.3
       ""NPM":"5.0.0-1","CLI":"8.0.0-master.10""
       Pixel Xl 7.1.1 Sim
       iphone x (ios13 sime)
       

JSON Source