Skip to content

Repository files navigation

eliware.org

@eliware/log npm versionlicensebuild status

A minimal, flexible logging library for Node.js, built on top of winston. Supports ESM, with TypeScript types included.


Table of Contents

Features

  • Simple, consistent logging API for Node.js
  • Built on winston
  • Supports ESM
  • Default and named exports for maximum flexibility
  • TypeScript type definitions included
  • Supports structured JSON output with optional timestamps
  • Supports child loggers with persistent context
  • Serializes Error objects with name, message, and stack
  • Supports configurable metadata redaction
  • Supports logging primitives and arrays as meta:
    • log.info('msg', 42) logs { value: 42 }
    • log.info('msg', [1,2,3]) logs { value: [1,2,3] }

Requirements

  • Node.js 26 or newer

Installation

npm install @eliware/log

Usage

ESM Example

// Example usage for ESMimportlog,{logasnamedLog,createLogger}from'@eliware/log';log.info('Hello from example.mjs (default import)',{foo: 'bar'});log.info('Primitive value',42);// primitive valuelog.info('Array value',[1,2,3]);// array valuenamedLog.info('Hello from example.mjs (named import)',{foo: 'bar'});namedLog.info('Primitive value','test');// primitive valueconstcustomLogger=createLogger({level: 'debug'});customLogger.debug('Custom logger debug message',{custom: true});customLogger.debug('Primitive debug',true);// primitive value

API

log (default and named export)

A pre-configured logger instance. Available as both the default and a named export (log).

  • .info(message, meta?)
  • .debug(message, meta?)
  • .warn(message, meta?)
  • .error(message, meta?)
  • ...and all other winston logger methods.

Meta argument:

  • If you pass a primitive or array as the second argument, it will be logged as { value: ... }.
  • If you pass an object, it will be logged as usual.

createLogger(options)

Creates a new winston logger instance.

Options:

  • level (string): Log level (default: process.env.LOG_LEVEL or 'info')
  • transports (array): Array of winston transports (default: Console)
  • format (text or json): Output format (default: text)
  • timestamp (boolean): Include timestamps in JSON output (default: false)
  • redactKeys (string[]): Metadata keys to redact, case-insensitively

Returns:winston.Logger

TypeScript

Type definitions are included:

exportdeclarefunctioncreateLogger(options?: {level?: string;transports?: import('winston').Transport[];format?: 'text'|'json';timestamp?: boolean;redactKeys?: string[];}): import('winston').Logger&{debug(message: string,meta?: unknown): void;info(message: string,meta?: unknown): void;warn(message: string,meta?: unknown): void;error(message: string,meta?: unknown): void;};exportdeclareconstlog: import('winston').Logger&{debug(message: string,meta?: unknown): void;info(message: string,meta?: unknown): void;warn(message: string,meta?: unknown): void;error(message: string,meta?: unknown): void;};exportdefaultlog;

Errors / Troubleshooting

Use redactKeys for sensitive metadata. Objects are shallowly summarized; nested object contents are not recursively serialized. Error fields are also subject to redaction. JSON output includes timestamps only when timestamp: true; text output safely summarizes objects and serializes BigInt values. Configure transports explicitly for tests and alternate destinations.

Development

npm test
npm run test:gaps
npm run lint
npm run typecheck
npm run pack

Security

Do not log secrets or sensitive payloads. Configure redactKeys for credential-bearing metadata and review custom transports before enabling them.

Support

For help, questions, or to chat with the author and community, visit:

Discordeliware.org

eliware.org on Discord

License

MIT © 2025 Eli Sterling, eliware.org

Links

Releases

Contributors

Languages