High-performance logging package for the Unchained Engine
npm install @unchainedshop/loggerA high-performance, feature-rich logging package for Unchained Engine with support for multiple formats, log levels, and debug patterns.
- 🚀 High Performance: Optimized for speed with caching and no-op functions for disabled log levels
- 🎨 Multiple Formats: Support for both human-readable (unchained) and JSON formats
- 🔍 Debug Patterns: Flexible DEBUG environment variable with wildcards and exclusions
- 📊 Log Levels: Five log levels (trace, debug, info, warn, error) with environment-based filtering
- 💪 TypeScript: Full TypeScript support with type definitions
- 🔧 Zero Dependencies: Core functionality with minimal external dependencies
``bash`
npm install @unchainedshop/logger
`typescript
import { createLogger } from '@unchainedshop/logger';
const logger = createLogger('my-module');
logger.info('Application started');
logger.debug('Debug information', { userId: 123 });
logger.error('Something went wrong', new Error('Details'));
`
#### UNCHAINED_LOG_FORMATunchained
Controls the output format:
- (default): Human-readable format with colorsjson
- : Machine-readable JSON format
`bash`
UNCHAINED_LOG_FORMAT=json node app.js
#### LOG_LEVELverbose
Sets the minimum log level:
- or trace: All logsdebug
- : Debug and aboveinfo
- (default): Info and abovewarn
- : Warnings and errors onlyerror
- : Errors only
`bash`
LOG_LEVEL=debug node app.js
#### DEBUGDEBUG=app:*
Enables debug logging for specific modules using pattern matching:
- Wildcards: DEBUG=*,-app:excluded
- Exclusions: DEBUG=app:,core:
- Multiple patterns:
`bash`
DEBUG=my-module,other:* node app.js
Creates a logger instance for the specified module.
Parameters:
- moduleName - The name of the module (used for filtering and display)
Returns: Logger instance with methods: trace, debug, info, warn, error
`typescript
import { log, defaultLogger } from '@unchainedshop/logger';
// Quick logging with default logger
log('Quick info message');
// Or use the default logger directly
defaultLogger.info('Info message');
``
See benchmarks/README.md for detailed performance metrics.
Key performance features:
- Zero-cost disabled logging: Log levels below the minimum use no-op functions
- Regex caching: Pattern matching results are cached for speed
- Optimized hot paths: Critical logging paths are optimized for maximum throughput