1.0.2 â€Ē Published 9 months ago

@bytware/logger v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

@bytware/logger

A structured, colorful logging utility designed for modern Node.js and Edge runtime environments, providing robust logging capabilities with zero dependencies and minimal overhead.

Features

  • 🚀 Edge Runtime compatible
  • ðŸŽĻ Colorful console output
  • ðŸ“Ķ Module-based logging
  • ðŸ‘Ī User context support
  • 🔍 Multiple log levels (debug, info, warn, error)
  • ⚙ïļ Configurable via environment variables
  • ðŸŽŊ TypeScript support
  • ðŸŠķ Zero dependencies
  • 🔒 Safe for sensitive environments
  • 🌐 Works in all Node.js environments

Installation

npm install @bytware/logger
# or
yarn add @bytware/logger
# or
pnpm add @bytware/logger

Usage

import logger from '@bytware/logger';

// Basic usage
logger.info('Application started');
logger.debug('Debug information', { someData: 123 });
logger.warn('Warning message');
logger.error('Error occurred', { error: new Error('Something went wrong') });

// Module-based logging
const authLogger = logger.child({ module: 'auth' });
authLogger.info('User logged in', { userId: '123' });

// Set user context
logger.setUserId('user-123')
  .info('Action performed by user');

// Clear user context
logger.setUserId(null);

Configuration

Set the log level using the LOG_LEVEL environment variable:

LOG_LEVEL=debug # Show all logs
LOG_LEVEL=info  # Show info and above (default)
LOG_LEVEL=warn  # Show only warnings and errors
LOG_LEVEL=error # Show only errors

Log Levels

  • debug: Detailed information for debugging
  • info: General operational events
  • warn: Warning conditions
  • error: Error conditions that should be investigated

Output Format

[DD/MM HH:MM:SS.mmm] LEVEL [module] [userId] message data

Server-Side Only Logging

For applications that need to ensure all logs are processed server-side (even when initiated from the client), see our Server-Side Logging Guide.

License

MIT

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago