[🇧🇷] Lê em português
A flexible and extensible TypeScript logger package based on the hexagonal architecture, with support for multiple output adapters, including console and files.
- Multiple log levels:
verbose
,info
,warn
,error
- Configurable minimum log level
- Simple and clean API
- TypeScript support
- Hexagonal architecture for easy extensibility
npm install @ericshantos/logger
import { Logger } from '@ericshantos/logger';
const logger = new Logger('info'); // 'info' is the default level
logger.verbose('This is a verbose message'); // Won't be logged if level is 'info'
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');
You can set the minimum log level when creating the logger:
const verboseLogger = new Logger('verbose'); // Will log all levels
const errorOnlyLogger = new Logger('error'); // Will log only errors
The package follows hexagonal architecture principles, making it easy to create custom adapters. Implement the LoggerContract
interface to create your own logger implementations.
import type { LoggerContract, LogLevel } from '@ericshantos/logger';
class CustomLogger implements LoggerContract {
// Implement all required methods
}
new Logger(level?: LogLevel = 'info')
verbose(message: string): void
info(message: string): void
warn(message: string): void
error(message: string): void
LogLevel
:'verbose' | 'info' | 'warn' | 'error'
LoggerContract
: Interface that all logger implementations must follow
npm run build
├── src
│ ├── core
│ │ ├── contracts # Core interfaces and types
│ │ └── logger.service.ts # Main logger implementation
│ └── index.ts # Public API exports
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.