A powerful, flexible logging library for TypeScript inspired by Apache Log4j, featuring colored output and emojis
npm install @rs-r2d2/log4tsA powerful, flexible logging library for TypeScript applications with colored output and emojis. Inspired by Apache Log4j, this library brings the robust logging patterns of Log4j to the TypeScript ecosystem.
Log4TS is inspired by Apache Log4j, bringing its proven logging patterns and concepts to TypeScript:
- Hierarchical logging architecture
- Multiple output appenders
- Customizable layouts
- Log levels
- Pattern-based formatting
While maintaining these core concepts, Log4TS adds modern features like:
- đ¨ Colored console output
- đ¯ TypeScript-first implementation
- đ Emoji indicators for different log levels
- đ Modern ES6+ features
- đ¨ Colored console output
- đ¯ Multiple log levels (TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
- đ§ Customizable layouts and patterns
- đ Emoji indicators for different log levels
- đ Placeholder substitution ({})
- ⥠Stack trace support for errors
- đ Extensible appender system
``bash`
npm install @rs-r2d2/log4ts
`typescript
import { LogManager, ConsoleAppender } from '@rs-r2d2/log4ts';
// Get a logger instance
const logger = LogManager.getLogger('MyApp');
// Add console appender
logger.addAppender(new ConsoleAppender());
// Log some messages
logger.info('Application started');
logger.debug('Processing data: {}', someData);
logger.error('An error occurred', error);
`
The library supports the following log levels (in order of severity):
- đ TRACE - Detailed debugging information
- đ DEBUG - Debugging information
- âšī¸ INFO - General information
- â ī¸ WARN - Warning messages
- â ERROR - Error messages
- đ FATAL - Critical errors that may cause application termination
The pattern layout supports the following placeholders:
- %d - Date/time%p
- - Log level%c
- - Logger name%m
- - Log message
Example:
`typescript`
new PatternLayout('[%d] [%p] %c - %m');
You can customize colors and icons for different log levels:
`typescript
const customConfig = new ColorConfig({
[LogLevel.INFO]: { color: 'blue', icon: 'â¨' }
});
const layout = new PatternLayout('[%d] [%p] %c - %m', customConfig);
const appender = new ConsoleAppender(layout);
`
Run the test suite:
`bash``
npm test
MIT