Registry / observability / log-util

log-util

JSON →
library2.3.0jsnpmunverified

log-util is a minimalist Node.js logging utility designed for terminal output. It provides a simple API for common log levels such as debug, info, success, warn, and error, allowing developers to categorize and display messages with distinct visual feedback in the console. The current stable version is 2.3.0. The package appears to be in a maintenance or stable state, with its last publish date being approximately six years ago (as of April 2026), indicating a lack of recent active development or frequent feature additions. Its primary differentiator is its simplicity and small footprint, offering basic logging capabilities without the extensive configuration or advanced features found in more comprehensive logging frameworks. It ships with TypeScript type definitions, enabling a typed development experience for users.

npm install log-util
INSTALL
IMPORT
SIG · LOG-UTIL
L
log-util
observabilityjavascriptv2.3.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.

log (CommonJS)
const log = require('log-util');
import log from 'log-util';
The package's primary usage examples and last major release predate widespread Node.js ESM adoption, making CommonJS the most reliable import method for direct usage.
log (ESM)
import log from 'log-util';
const log = require('log-util');
While `log-util` ships with TypeScript types, direct ESM import might require Node.js configuration (e.g., `"type": "module"` in `package.json`) or a bundler to correctly resolve the CommonJS default export.
LogUtil (Type)
import type { LogUtil } from 'log-util';
For TypeScript users, importing the `LogUtil` type allows for strong typing of the `log` object, leveraging the provided type definitions.

Demonstrates importing `log-util`, setting the global log level, using various logging methods, and creating a separate `Log` instance with its own level.

import log from 'log-util'; // Set the global log level to 'info' log.setLevel('info'); console.log('--- Default Logger (Level: Info) ---'); log.debug('This is a debug message (should not appear)'); log.info('This is an info message (level: 1)', { user: 'Alice' }); log.success('Operation completed successfully (level: 2)'); log.warn('A warning occurred (level: 3)'); log.error('An error happened (level: 4)', new Error('Something went wrong')); // Create a new Log instance with a custom level // The 'Log' constructor is exposed on the default 'log' object const customLogger = new log.Log(log.levels.debug); console.log('\n--- Custom Logger (Level: Debug) ---'); customLogger.setLevel('debug'); // Set instance level to debug customLogger.debug('This is a debug message from custom logger (level: 0)'); customLogger.info('Info from custom logger (level: 1)', [1, 2, 3]); customLogger.success('Success from custom logger (level: 2)'); // Demonstrate changing level mid-execution console.log('\n--- Changing Level on Default Logger ---'); log.setLevel('error'); log.info('This info message will not appear now.'); log.error('Only error messages will show (level: 4) after changing level.');
Debug
Known issues
gotchaThe package is primarily designed for CommonJS (`require`) usage, and its ESM (`import`) interoperability relies on Node.js's module resolution for CommonJS default exports. Direct ESM usage might lead to unexpected behavior in certain Node.js environments or older bundlers without proper configuration.
fix
For Node.js projects, ensure `package.json` has `"type": "module"` for full ESM support or explicitly use `require()` for this package. If using a bundler, verify its CommonJS interoperability settings.
affects: >=1.0.0
gotchaThe `log.setLevel()` method globally modifies the logging level for all subsequent `log` calls (unless a new `Log` instance is created). This can lead to unexpected filtering if different parts of an application expect independent logging verbosity.
fix
For isolated logging contexts, instantiate `new log.Log(initialLevel)` for each context instead of relying on the globally modified `log` object. Remember that `log.Log` is a constructor accessible via the default export.
affects: >=1.0.0
deprecatedThe `log-util` package has not seen updates in approximately six years (since its last publish date in June 2019). While functional, it may lack modern features, performance optimizations, or compatibility with newer Node.js versions or TypeScript constructs compared to actively maintained logging libraries.
fix
For new projects or those requiring active maintenance, consider modern logging solutions like Winston, Pino, or tslog. If maintaining `log-util`, thoroughly test its behavior in your target environment.
affects: <2.3.0
Errors
Common errors & fixes
TypeError: log.debug is not a function
Attempting to use `log.debug` (or other methods) after an incorrect ESM import, where `log` might be `undefined` or not the expected object.
fix
Ensure you are using `import log from 'log-util';` for ESM, or `const log = require('log-util');` for CommonJS. If using `import * as log from 'log-util'`, methods might be nested, e.g., `log.default.debug`.
SyntaxError: Cannot use import statement outside a module
This error occurs when using ESM `import` syntax in a Node.js file that is being treated as a CommonJS module (default behavior for `.js` files without explicit configuration).
fix
To use ESM imports, either rename your file to `.mjs`, or add `"type": "module"` to your project's `package.json` file. Alternatively, switch back to CommonJS `require()` syntax for this package.
ReferenceError: require is not defined
This happens when `require()` is called in a file that Node.js is treating as an ES Module (e.g., `.mjs` file or `"type": "module"` in `package.json`), where `require` is not globally available.
fix
For ES Modules, use the `import` statement: `import log from 'log-util';`. If you need to load CommonJS modules within an ES module, consider using `import { createRequire } from 'module'; const require = createRequire(import.meta.url);` as a workaround for specific cases.
Upgrade
Version history
2.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
log-util — npm install log-util · libregistry