1.0.2 âĒ Published 9 months ago
@bytware/logger v1.0.2
@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/loggerUsage
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 errorsLog Levels
debug: Detailed information for debugginginfo: General operational eventswarn: Warning conditionserror: Error conditions that should be investigated
Output Format
[DD/MM HH:MM:SS.mmm] LEVEL [module] [userId] message dataServer-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