Logging

Logging messages, warnings and errors with the module name.

Logging methods

mod.log(...args), mod.warn(...args) and mod.error(...args) print regular messages, warnings and errors. Toolbox prefixes the module name so users can identify the source.

mod.log('Module initialized');
mod.warn('Optional feature is unavailable');
try {
    mod.send('S_CHAT', 3, { name: 'Example', message: 'Hello' });
} catch (error) {
    mod.error('Unable to send the message:', error);
}

Use template strings or separate arguments. Do not rely on %s substitutions as in the first argument of console.log: Toolbox inserts its own prefix before your arguments.

Practice

Use logs for background diagnostics and mod.command.message for command replies. Frequent packets can generate thousands of lines, so put verbose logging behind a setting. Error messages benefit from the operation, packet name and definition version; avoid publishing tokens, keys or complete network dumps unnecessarily.

Sources: doc/mod/logging.md, bin/mod.js.