Logging
The built-in logging API is useful for debugging. Output logs can be viewed both in the logging panel in the Web Editor or in the logging display within the Enklu HoloLens app.
Logging Levels
The logging API supports 4 levels of logging: debug, info, warning, and error. Output logs are formatted starting with the log level, then the timestamp for the log, then the contents of the log. System logs use these same log levels and formatting:
Debug
A debug level log in a Behavior script:
log.debug('A debug level log.');
This log would output to the logging panel in the Web Editor like this:
Info
An info level log in a Behavior script:
log.info('Hello! I am an info level log.');
This log would output to the logging panel in the Web Editor like this:
Warning
A warning level log in a Behavior script:
log.warn('Warning, this is a warning level log.');
This log would output to the logging panel in the Web Editor like this:
Error
An error level log in a Behavior script:
log.error('Error... this is a correctly output error log.');
This log would output to the logging panel in the Web Editor like this:
Variables and String Replacement
Variables can be logged directly. Logging a variable could look like this:
const somethingCool = 'Turtles';
log.info(somethingCool);
This script would output to the logging panel in the Web Editor like this:
Each logging method also supports C# style string replacement using curly braces {}
. Logging a variable using string replacement could look like this:
const somethingCool = 'Turtles';
log.info('Wanna know something cool? {0} are cool.', somethingCool);
This script would output to the logging panel in the Web Editor like this: