Skip to content

setLoggingLevel()

setLoggingLevel() sets the global logging verbosity for ResourceLoader.js. This is useful for silencing the library in production or enabling verbose output during development.

ResourceLoader.setLoggingLevel(level: 'silent' | 'warn' | 'verbose'): void
ParameterTypeDescription
level'silent' | 'warn' | 'verbose'The logging level to use

LevelConsole output
'silent'Nothing — no console output at all
'warn'Warnings and errors only (console.warn) — this is the default
'verbose'All messages, including successful load confirmations (console.log)

No output whatsoever. Use in production to keep the console clean:

ResourceLoader.setLoggingLevel('silent');

Only important messages such as missing integrity attributes, invalid option values, and load failures. You do not need to call this explicitly — it is the default.

ResourceLoader.setLoggingLevel('warn');

Everything — useful during development to see exactly what is happening:

ResourceLoader.setLoggingLevel('verbose');
// Console will show:
// [ResourceLoader] Loading: https://cdn.example.com/app.js
// [ResourceLoader] Loaded: https://cdn.example.com/app.js
// etc.

The logLevel option on include() and setLoggingLevel() both set the same global logging level. They are equivalent. Whichever is called last takes effect:

// These two are equivalent:
ResourceLoader.setLoggingLevel('verbose');
ResourceLoader.include(['https://cdn.example.com/app.js'], {
logLevel: 'verbose',
});

setLoggingLevel() is useful when you want to set the level once at startup rather than passing logLevel to every include() call.


// At the top of your app's entry point
if (process.env.NODE_ENV === 'production') {
ResourceLoader.setLoggingLevel('silent');
} else {
ResourceLoader.setLoggingLevel('verbose');
}
async function debugLoad(url) {
ResourceLoader.setLoggingLevel('verbose');
try {
await ResourceLoader.include([url]);
} finally {
ResourceLoader.setLoggingLevel('warn'); // Restore default
}
}

  • Passing an invalid level (e.g., 'debug') falls back to 'warn' and logs a console warning about the invalid value.
  • The level set by setLoggingLevel() persists for the lifetime of the page until changed again.