{"id":11247,"library":"log-util","title":"Node.js Log Utility","description":"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.","status":"maintenance","version":"2.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/vivaxy/log-util","tags":["javascript","log","typescript"],"install":[{"cmd":"npm install log-util","lang":"bash","label":"npm"},{"cmd":"yarn add log-util","lang":"bash","label":"yarn"},{"cmd":"pnpm add log-util","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import log from 'log-util';","symbol":"log (CommonJS)","correct":"const log = require('log-util');"},{"note":"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.","wrong":"const log = require('log-util');","symbol":"log (ESM)","correct":"import log from 'log-util';"},{"note":"For TypeScript users, importing the `LogUtil` type allows for strong typing of the `log` object, leveraging the provided type definitions.","symbol":"LogUtil (Type)","correct":"import type { LogUtil } from 'log-util';"}],"quickstart":{"code":"import log from 'log-util';\n\n// Set the global log level to 'info'\nlog.setLevel('info');\n\nconsole.log('--- Default Logger (Level: Info) ---');\nlog.debug('This is a debug message (should not appear)');\nlog.info('This is an info message (level: 1)', { user: 'Alice' });\nlog.success('Operation completed successfully (level: 2)');\nlog.warn('A warning occurred (level: 3)');\nlog.error('An error happened (level: 4)', new Error('Something went wrong'));\n\n// Create a new Log instance with a custom level\n// The 'Log' constructor is exposed on the default 'log' object\nconst customLogger = new log.Log(log.levels.debug);\n\nconsole.log('\\n--- Custom Logger (Level: Debug) ---');\ncustomLogger.setLevel('debug'); // Set instance level to debug\ncustomLogger.debug('This is a debug message from custom logger (level: 0)');\ncustomLogger.info('Info from custom logger (level: 1)', [1, 2, 3]);\ncustomLogger.success('Success from custom logger (level: 2)');\n\n// Demonstrate changing level mid-execution\nconsole.log('\\n--- Changing Level on Default Logger ---');\nlog.setLevel('error');\nlog.info('This info message will not appear now.');\nlog.error('Only error messages will show (level: 4) after changing level.');\n","lang":"typescript","description":"Demonstrates importing `log-util`, setting the global log level, using various logging methods, and creating a separate `Log` instance with its own level."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":"<2.3.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"Attempting to use `log.debug` (or other methods) after an incorrect ESM import, where `log` might be `undefined` or not the expected object.","error":"TypeError: log.debug is not a function"},{"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.","cause":"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).","error":"SyntaxError: Cannot use import statement outside a module"},{"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.","cause":"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.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}