The `log` package provides a universal and pluggable logging utility designed for JavaScript applications, currently stable at version 6.3.2. It focuses on being configurable, environment, and presentation agnostic, differentiating itself by not handling output directly but emitting events for external 'writers' (e.g., `log-node` for Node.js environments). Releases are made as needed, with several maintenance and minor feature updates occurring within the last few years. Key features include syslog-compatible log levels (debug, info, notice, warning, error), `debug`-style namespacing for granular control, and support for printf-like message formatting with various placeholders (e.g., `%s`, `%d`, `%j`, `%o`). This design allows developers to write application logs once and integrate different output mechanisms without changing core logging logic. It does not expose `critical`, `alert`, or `emergency` levels, expecting these to be handled as typical exceptions. A crucial differentiator is its modular approach, requiring an explicit 'writer' package to actually emit log messages, making it highly adaptable to various runtime environments and output formats.
npm install logVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the log system with `log-node`, creating default and namespaced loggers, logging at different levels, and dynamic enabling/disabling of log output.
Review the migration guide if you were using custom writers directly manipulating the internal master writer registration. For most users, updating `log-node` or other specific writer packages should resolve this.
Adjust any custom code that directly compares or interprets log levels based on their numerical index. Rely on the named level methods (e.g., `log.error`, `log.debug`) rather than their underlying numerical values for future compatibility.
Install a suitable writer package (e.g., `npm install log-node`) and ensure it is initialized at your application's entry point (e.g., `import 'log-node';` or `require('log-node')();`).For conditions that would typically map to `critical`, `alert`, or `emergency` severity, use standard JavaScript error handling mechanisms (e.g., throwing and catching exceptions, process error handlers) instead of attempting to log them through this utility.
Install and initialize a writer package, such as `log-node`, at the entry point of your application. Example: `npm install log-node` then `import 'log-node';` or `require('log-node')();`.Ensure your code, especially any custom writers or filters, is aware of the reversed level indexing if you are comparing levels by their numerical values. It's safer to use the named methods (e.g., `log.error()`, `log.debug()`) rather than relying on index values.