How to disable the logging of BabylonJS version in NullEngine?

I’m using NullEngine to write unit tests (as the documentation suggests).

But when I instantiate it:

new NullEngine();

I get the following printed to the console:

BJS - [10:18:31]: Babylon.js v7.42.0 - Null engine

Similar log entry also appears when using the actual Engine, but with NullEngine this is a real bummer. It just introduces useless noise when running the tests. How could I disable this?

I see that inside NullEngine constructor that it uses Logger:

Logger.Log(`Babylon.js v${Engine.Version} - Null engine`);

Perhaps there’s some way to disable the logger? I looked at the documentation of Logger but failed to find a way to disable the logging.

Possibly I could change my test environment to replace the console.log with some dummy function that does nothing. But I’d really leave it as a last resort.

1 Like

After digging through Logger implementation, I finally discovered a way to disable the logging:

Logger.LogLevels = Logger.NoneLogLevel;

The documentation of LogLevels attribute only says the following:

Sets the current log level (MessageLogLevel / WarningLogLevel / ErrorLogLevel)

This is terribly confusing. Like why is the name plural when the docs say that it sets just a single log level? And it doesn’t say anything about being able to use NoneLogLevel or AllLogLevel with this attribute.

Turns out that these log levels are encoded as a bitmap. And you can set any combination of them (or none at all) by combining the values with bitwise-or:

Logger.LogLevel = Logger.MessageLogLevel | Logger.WarningLogLevel | Logger.ErrorLogLevel;
3 Likes

I tried to improve the doc:

4 Likes