Skip to content

Modular and extensible TypeScript logger with hexagonal architecture, for flexible and easy-to-maintain Node.js applications.

License

Notifications You must be signed in to change notification settings

ericshantos/logger.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[🇧🇷] Lê em português

Logger.js

License: MIT TypeScript

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

npm install @ericshantos/logger

Usage

Basic Usage

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:

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.

import type { LoggerContract, LogLevel } from '@ericshantos/logger';

class CustomLogger implements LoggerContract {
    // Implement all required methods
}

API Reference

Logger Class

Constructor

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

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 file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

About

Modular and extensible TypeScript logger with hexagonal architecture, for flexible and easy-to-maintain Node.js applications.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published