https://github.com/ericshantos/logger.js
Modular and extensible TypeScript logger with hexagonal architecture, for flexible and easy-to-maintain Node.js applications.
https://github.com/ericshantos/logger.js
logger typescripts
Last synced: 11 months ago
JSON representation
Modular and extensible TypeScript logger with hexagonal architecture, for flexible and easy-to-maintain Node.js applications.
- Host: GitHub
- URL: https://github.com/ericshantos/logger.js
- Owner: ericshantos
- License: mit
- Created: 2025-07-12T12:40:56.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-12T19:33:09.000Z (12 months ago)
- Last Synced: 2025-07-12T20:32:02.452Z (12 months ago)
- Topics: logger, typescripts
- Language: TypeScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[π§π·] [LΓͺ em portuguΓͺs](./README.pt.md)
# Logger.js
[](https://opensource.org/licenses/MIT)
[](https://www.typescriptlang.org/)
A flexible and extensible TypeScript logger package based on the hexagonal architecture, with support for multiple output adapters, including console and files.
## Features
- Multiple log levels: `verbose`, `info`, `warn`, `error`
- Configurable minimum log level
- Simple and clean API
- TypeScript support
- Hexagonal architecture for easy extensibility
## Installation
```bash
npm install @ericshantos/logger
```
## Usage
### Basic Usage
```typescript
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');
```
### Custom Log Levels
You can set the minimum log level when creating the logger:
```typescript
const verboseLogger = new Logger('verbose'); // Will log all levels
const errorOnlyLogger = new Logger('error'); // Will log only errors
```
### Extending the Logger
The package follows hexagonal architecture principles, making it easy to create custom adapters. Implement the `LoggerContract` interface to create your own logger implementations.
```typescript
import type { LoggerContract, LogLevel } from '@ericshantos/logger';
class CustomLogger implements LoggerContract {
// Implement all required methods
}
```
## API Reference
### `Logger` Class
#### Constructor
```typescript
new Logger(level?: LogLevel = 'info')
```
#### Methods
- `verbose(message: string): void`
- `info(message: string): void`
- `warn(message: string): void`
- `error(message: string): void`
### Types
- `LogLevel`: `'verbose' | 'info' | 'warn' | 'error'`
- `LoggerContract`: Interface that all logger implementations must follow
## Development
### Building the Project
```bash
npm run build
```
### Project Structure
```
βββ src
β βββ core
β β βββ contracts # Core interfaces and types
β β βββ logger.service.ts # Main logger implementation
β βββ index.ts # Public API exports
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Contributing
Contributions are welcome! Please open an issue or submit a pull request.