Registry / observability / loglevel-colored-level-prefix

loglevel-colored-level-prefix

JSON →
library1.0.0jsnpmunverified

The `loglevel-colored-level-prefix` package is a specialized plugin for the `loglevel` library, designed to enhance log output in Node.js environments by adding colored prefixes to log levels. Released as `v1.0.0` in February 2017, this utility provides a stable, opinionated solution for visually distinct logging but is not under active development, operating effectively in a maintenance-only status. It explicitly leverages the `chalk` library for terminal colorization, making it a Node.js-exclusive tool and unsuitable for browser environments. Its primary differentiator is offering a consistent, pre-formatted log style specifically for Node.js applications, aiding in quick identification of log severity. The package exposes a single function, `getLogger`, which returns a singleton `loglevel` instance, configured with a specified prefix and initial log level, providing a focused approach to colored console output within the `loglevel` ecosystem.

npm install loglevel-colored-level-prefix
INSTALL
IMPORT
SIG · LOGLEVEL-COLORED-L
L
loglevel-colored-level-prefix
observabilityjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getLogger
const getLogger = require('loglevel-colored-level-prefix')
import getLogger from 'loglevel-colored-level-prefix'
This package is CommonJS-only and does not support ESM `import` syntax.
getLogger (destructuring)
const getLogger = require('loglevel-colored-level-prefix')
const { getLogger } = require('loglevel-colored-level-prefix')
The module exports `getLogger` as its default; it is not a named export.
Logger instance
const logger = getLogger({ prefix: 'APP', level: 'info' })
const logger = new getLogger()
`getLogger` is a factory function, not a constructor. It returns a singleton logger instance based on the prefix.

Initializes and demonstrates logging at different levels using `getLogger` with colored prefixes in a Node.js environment.

const getLogger = require('loglevel-colored-level-prefix'); // Options can include 'prefix' (string) and 'level' (string: trace, debug, info, warn, error) const options = { prefix: 'MY_APP', level: 'trace' }; const logger = getLogger(options); logger.trace('Tracing execution flow. Data: %o', { user: 'test', id: 123 }); logger.debug('Debugging an issue. Variable X is: %d', 42); logger.info('User logged in. ID: %s', 'user-abc-123'); logger.warn('Deprecated API call detected in module: %s', 'old-module'); logger.error('Critical error occurred! Stack: %s', new Error('Something went wrong').stack); // Subsequent calls with the same prefix will return the same logger instance const anotherLogger = getLogger({ prefix: 'MY_APP' }); logger.info('This is the same logger instance as before:', logger === anotherLogger);
Debug
Known issues
breakingThis package is strictly designed for Node.js environments. It utilizes Node.js-specific APIs and the `chalk` library for terminal output, rendering it incompatible with browser-based applications.
fix
Do not use this package in browser environments. For browser-compatible colored logging, consider other `loglevel` plugins or custom formatting solutions that do not rely on Node.js-specific modules.
affects: >=1.0.0
breakingThe package is a CommonJS module and does not natively support ECMAScript Modules (ESM) `import` syntax. Attempting to `import` it directly in an ESM context will result in a runtime error.
fix
If using an ESM project, you must use `require` via `createRequire` or dynamically import using `import()` if supported by your environment and build tools. For example: `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const getLogger = require('loglevel-colored-level-prefix');`
affects: >=1.0.0
gotchaThe package has not seen updates since its `v1.0.0` release in 2017. While stable for its intended purpose, it might not be compatible with very recent major versions of `loglevel` or `chalk` if they introduce breaking changes.
fix
Always test compatibility when upgrading `loglevel` or `chalk`. If issues arise, consider forking the repository or finding alternative, actively maintained solutions for colored logging.
affects: >=1.0.0
gotchaThe `getLogger` function returns a singleton logger instance per unique `prefix` value. If you call `getLogger` multiple times with the same `prefix`, you will receive the same logger instance. This means level changes on one instance will affect all references with that prefix.
fix
Be aware of the singleton behavior. If you require truly independent logger instances, ensure you use distinct `prefix` values or manually create and manage separate `loglevel` instances with this plugin applied.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ECMAScript Module (ESM) context without proper setup.
fix
If in an ESM module, you need to import `require` explicitly: `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const getLogger = require('loglevel-colored-level-prefix');`
TypeError: getLogger is not a function
Incorrectly attempting to destructure `getLogger` from the `require` call, or attempting to use `import { getLogger } ...` in an ESM context.
fix
The module exports `getLogger` as its default. Use `const getLogger = require('loglevel-colored-level-prefix');` for CommonJS. For ESM, follow the `createRequire` pattern for `require` and assign the result directly.
process is not defined
Running the package in a browser environment where the global `process` object (used for `process.env.LOG_LEVEL`) is not available.
fix
This package is Node.js-only. Do not include or execute it in browser bundles. For front-end logging, use browser-compatible `loglevel` plugins or custom solutions.
No colors in output despite correct usage
The terminal or environment might not support ANSI escape codes, or `chalk` might be detecting a non-TTY environment.
fix
Ensure your terminal supports colors. Some CI/CD environments might disable color output by default. You can often force `chalk` to output colors by setting `FORCE_COLOR=1` in your environment variables, e.g., `FORCE_COLOR=1 node your-script.js`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
loglevelrequiredCore logging library that this package extends.
chalkrequiredProvides terminal colorization for log prefixes.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources