Allow context aware Logging with additional arguments

The current [logger.ts] (Babylon.js/logger.ts at 383f2b61e544293eb712362eda66477e30243251 · BabylonJS/Babylon.js · GitHub) class expects a string and an optional limit argument.

It would be nice to make it context aware so that multiple arguments can be passed to the browser implementation of console.log and be able to print out formatted objects and arrays.

Current implementation:

Logger.Log(message, limit) ---maps to---> console.log('BJS - ' + formattedMessage);


Logger.Log(obj1, ..., objN) ---should ideally map to---> console.log(obj1,  ..., objN);

What do you think? Is there some reason to keep this feature out of @bablyonjs/core?

1 Like

ping @DarraghBurke

What would happen to the limit parameter? If someone calls Log("hello",2) should that print “hello 2” or “hello” with a limit of two prints? We need to make sure we are maintaining backwards compatibility here.

We also may need to think about Babylon Native. How is the Logger implemented on Native? Are we just polyfilling console.log or does Logger have a separate implementation? @Cedric

Yes, it’s a polyfill with log, warn and error methods.

1 Like

Why not call console.log directly?

Ideally I’d like to have an interface for logging. It would make the whole code less clunky and portable, especially if I have to handle logging levels for console.log statements and the Babylon logger.
I am also ok using something like the “loglevel” library or just plain old console.log statements (which i am currently doing). I just wanted to start a discussion by asking if this feature would make sense or if it is a questionable wish.

I think it will be difficult to do given what @DarraghBurke said above unless we add functions with different names, but I’m not sure that’s a good idea.

1 Like