Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3303] Ti API: log support for multiple arguments

GitHub Issuen/a
TypeImprovement
Priorityn/a
StatusClosed
ResolutionWon't Fix
Resolution Date2012-01-05T09:39:38.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsStudio
Labelstc-more-info
ReporterSindre Sorhus
AssigneeShak Hossain
Created2011-10-19T11:07:04.000+0000
Updated2016-03-08T07:57:43.000+0000

Description

Feature Request

Add support for multiple arguments to logging methods.

Test case

Ti.API.log({sdf:"df"}, [1,3,5,6], "sdfsdf");

Logs

With the above code, you would see the following result:
Object [1,3,5,6] "sdfsdf"
Also see attached image

Attachments

FileDateSize
Screen Shot 2011-10-19 at 21.03.43.png2011-10-19T11:07:04.000+000011223

Comments

  1. Matthew Apperson 2011-10-20

    Thank you for raising this ticket. I am afraid we need all the information listed in the [Jira Ticket Checklist](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-Summary%3AJiraTicketChecklist) in order to accept a ticket. Once this ticket is complete, we can move it to the main project. Thank you
  2. Sindre Sorhus 2011-10-21

    Fixed.
  3. Sindre Sorhus 2012-01-02

    Can someone reopen this?
  4. Paul Dowsett 2012-01-02

    Sindre Please ensure your requests are consistent. For instance, the example code produces the results you've included. I will escalate this now. Thanks for raising it. Thank you
  5. Paul Dowsett 2012-01-02

    On second thoughts, I agree with the reasons that I presume Matt marked this as invalid, although he should have provided his reasons. Arguments can be concatenated in Javascript. For example:
       Ti.API.log({sdf:"df"} + ' ' + [1,3,5,6] + ' ' +  "sdfsdf");
       
    Why isn't this sufficient?
  6. Paul Dowsett 2012-01-05

    Thanks for your input here. Having verified with one of our engineering project leads, the above solution is the recommended approach. I'm closing this ticket now.
  7. Paul Dowsett 2012-01-05

    Sindre I realise that you are capable of writing this, but a colleague of mine kindly wrote it for you. It's not been tested, but I am sure it's almost there. Cheers
       exports.log = function() {
           var log = '';
           for(var i = 0, len = arguments.length; i < len; i++){
               switch(typeof(arguments[i])) {
                   case 'object':
                   case 'array':
                       log += ' '+JSON.stringify(arguments[i]);
                   break;
                   case 'string':
                   case 'number':
                       log += ' '+arguments[i];
                   break;
                   case 'boolean':
                       log += ' '+ (arguments[i]) ? 'true' : 'false';
                   break;
                   case 'undefined':
                       log += ' undefined';
                   break;
                   default:
                       log += ' null';
               }
           }
           Ti.API.info(log);
       };
       
       var console = require('/logger');
       console.log({sdf:"df"}, [1,3,5,6], "sdfsdf");
       

JSON Source