Universal pluggable logging utility with configurable levels and namespacing support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Primary logging functionality with five severity levels based on syslog standards. Supports printf-style message formatting and provides both callable logger functions and level-specific methods.
The default export is a callable logger function operating at 'info' level.
/**
* Main logger function - logs at 'info' level
* @param {*} message - Primary message (string with printf placeholders or any value)
* @param {...*} args - Arguments for printf-style formatting
*/
function log(message, ...args);Usage Examples:
const log = require("log");
// Simple string logging
log("Application started");
log("User logged in");
// Printf-style formatting
log("User %s logged in with ID %d", "alice", 123);
log("Processing %d items", 42);
log("Config: %j", { debug: true, port: 3000 });Each logger provides access to all five logging levels as properties/methods.
/**
* Debug level logger - for debugging information (hidden by default)
* @param {*} message - Message to log
* @param {...*} args - Arguments for formatting
*/
log.debug(message, ...args);
/**
* Info level logger - for informational messages (hidden by default)
* @param {*} message - Message to log
* @param {...*} args - Arguments for formatting
*/
log.info(message, ...args);
/**
* Notice level logger - for significant conditions (visible by default)
* @param {*} message - Message to log
* @param {...*} args - Arguments for formatting
*/
log.notice(message, ...args);
/**
* Warning level logger - for warning conditions (visible by default)
* @param {*} message - Message to log
* @param {...*} args - Arguments for formatting
*/
log.warning(message, ...args);
/**
* Warn level logger - alias for warning level
* @param {*} message - Message to log
* @param {...*} args - Arguments for formatting
*/
log.warn(message, ...args);
/**
* Error level logger - for error conditions (visible by default)
* @param {*} message - Message to log
* @param {...*} args - Arguments for formatting
*/
log.error(message, ...args);Usage Examples:
const log = require("log");
// Different severity levels
log.error("Database connection failed: %s", error.message);
log.warning("Deprecated API used in %s", functionName);
log.notice("Server started on port %d", 3000);
log.info("Processing request %s", requestId);
log.debug("Variable state: %j", debugObject);
// Level chaining - all return the same logger instance
log.info === log; // true
log.error.info === log; // true
log.warning.debug.error === log.error; // trueEach logger exposes properties describing its level configuration.
/**
* Current logger level name
* @type {string}
*/
log.level;
/**
* Numeric index of logger level (0=error, 1=warning, 2=notice, 3=info, 4=debug)
* @type {number}
*/
log.levelIndex;
/**
* Reference to the root logger for this level
* @type {Logger}
*/
log.levelRoot;Usage Examples:
const log = require("log");
console.log(log.level); // "info"
console.log(log.levelIndex); // 3
console.log(log.error.level); // "error"
console.log(log.error.levelIndex); // 0
// Root logger reference
const nsLogger = log.get("mylib");
console.log(nsLogger.levelRoot === log); // trueMethods for inspecting and managing logger level initialization.
/**
* Check if a logger for the specified level has been initialized
* @param {string} level - Level name to check
* @returns {boolean} True if level logger exists
*/
log.isLevelInitialized(level);
/**
* Get all initialized level loggers for the current namespace
* @returns {Logger[]} Array of initialized logger instances
*/
log.getAllInitializedLevels();Usage Examples:
const log = require("log");
// Check level initialization
console.log(log.isLevelInitialized("info")); // true
console.log(log.isLevelInitialized("debug")); // false (until first access)
console.log(log.isLevelInitialized("custom")); // false (not a valid level)
// Access debug logger to initialize it
log.debug("test");
// Now debug is initialized
console.log(log.isLevelInitialized("debug")); // true
// Get all initialized levels
const levels = log.getAllInitializedLevels();
console.log(levels.map(l => l.level)); // ["info", "debug"]The log package supports printf-style message formatting with the following placeholders:
%s - String%d - Number (integer or floating point value)%i - Integer%f - Floating point value%j - JSON (with circular reference handling)%o - Object representation with hidden properties%O - Object representation without hidden properties%% - Literal percent signFormatting Examples:
const log = require("log");
// String formatting
log("Hello %s", "world"); // "Hello world"
// Number formatting
log("Count: %d, Price: %f", 42, 19.99); // "Count: 42, Price: 19.99"
// JSON formatting
log("Config: %j", { port: 3000, debug: true }); // "Config: {"port":3000,"debug":true}"
// Object formatting
log("User: %o", user); // Detailed object output
log("Simple: %O", user); // Simple object output
// Literal percent
log("Progress: 50%%"); // "Progress: 50%"By default, the log package follows syslog severity ordering:
The visibility threshold can be configured via environment variables or programmatically through log writers.