eazy-logger
eazy-logger is a lightweight command-line interface (CLI) logging utility designed for Node.js environments. It provides basic logging levels (debug, info, warn, error) and supports `printf`-style string substitution for dynamic message formatting. A key feature is its integration with `tfunk` for customizable, colorful console output, allowing developers to define prefixes and style messages with various colors. The current stable version is 4.1.0, released over a year ago. The project is in maintenance mode, with minimal activity primarily focused on critical fixes rather than new feature development, as indicated by its 'Inactive' status on Snyk. Its primary differentiators are its simplicity and built-in support for styled terminal output without external color libraries.
Common errors
-
ReferenceError: require is not defined in ES module scope
cause Attempting to use `require()` in a JavaScript file that Node.js treats as an ES module (e.g., due to `"type": "module"` in `package.json` or a `.mjs` file extension).fixEither convert your project to CommonJS (remove `"type": "module"`), rename the file to `.cjs`, or use dynamic import with `const eazyLogger = await import('eazy-logger'); const { Logger } = eazyLogger;`. -
Property 'Logger' does not exist on type 'typeof import("/path/to/node_modules/eazy-logger/index")'.cause This error occurs in TypeScript when the `eazy-logger` package is imported without type definitions, and TypeScript cannot infer the structure of the module export.fixCreate a `eazy-logger.d.ts` declaration file in your project to define the module's structure and the `Logger` class. See the 'Warnings' section for a basic example.
Warnings
- breaking The package is CommonJS-only and will not work directly with ES module `import` syntax in modern Node.js environments unless transpiled or dynamically imported. Attempting to `import` it will result in a runtime error.
- gotcha The project is in 'inactive' maintenance mode, meaning new features are unlikely, and compatibility with future Node.js versions or emerging JavaScript standards (like native TypeScript support) may not be guaranteed. While a security fix was applied recently, ongoing proactive maintenance is limited.
- gotcha There are no official TypeScript type definitions shipped with the package, nor are there community-maintained types on `@types/eazy-logger`. This leads to type errors when used in TypeScript projects.
Install
-
npm install eazy-logger -
yarn add eazy-logger -
pnpm add eazy-logger
Imports
- Logger
import { Logger } from 'eazy-logger';const { Logger } = require('eazy-logger'); - logger
import logger from 'eazy-logger';
const logger = require('eazy-logger').Logger({ /* config */ }); - eazyLogger
import * as eazyLogger from 'eazy-logger';
const eazyLogger = require('eazy-logger'); const logger = eazyLogger.Logger({ /* config */ });
Quickstart
const { Logger } = require('eazy-logger');
const logger = Logger({
prefix: "{blue:[}{magenta:easy-logger}{blue:] }",
useLevelPrefixes: true
});
console.log('--- Standard Loggers ---');
logger.debug("Debugging Msg");
logger.info("Info statement");
logger.warn("A little warning with string %s", "substitution");
logger.error("An error occurred in file: {red:%s}", "/users/awesomedev/file.js");
console.log('\n--- String Substitution + Colours ---');
logger.log("error", "Use {green:built-in} %s", "String substitution");
console.log('\n--- Set Option for Next Log Only ---');
logger.setOnce("useLevelPrefixes", false).warn("This warning will not have a level prefix.");
logger.info("This info statement will use prefixes again.");