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.
Signature
Section titled “Signature”ResourceLoader.setLoggingLevel(level: 'silent' | 'warn' | 'verbose'): voidParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
level | 'silent' | 'warn' | 'verbose' | The logging level to use |
Logging Levels
Section titled “Logging Levels”| Level | Console 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) |
'silent'
Section titled “'silent'”No output whatsoever. Use in production to keep the console clean:
ResourceLoader.setLoggingLevel('silent');'warn' (default)
Section titled “'warn' (default)”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');'verbose'
Section titled “'verbose'”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.Relationship to the logLevel Option
Section titled “Relationship to the logLevel Option”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.
Examples
Section titled “Examples”Production Setup
Section titled “Production Setup”// At the top of your app's entry pointif (process.env.NODE_ENV === 'production') { ResourceLoader.setLoggingLevel('silent');} else { ResourceLoader.setLoggingLevel('verbose');}Temporarily Enable Verbose Logging
Section titled “Temporarily Enable Verbose Logging”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.