@wroud/api-logger

0.1.1 • Public • Published

@wroud/api-logger

ESM-only package NPM version

@wroud/api-logger is a lightweight and flexible logging interface library for JavaScript and TypeScript applications. It provides a standardized way to implement logging across your projects, ensuring consistency and ease of maintenance. Designed with modern JavaScript features in mind, it seamlessly integrates with various logging implementations.

Features

  • TypeScript Support: Fully typed interfaces for enhanced developer experience.
  • ESM-only Package: Utilizes ES modules for optimal performance and compatibility.
  • Flexible Logging Levels: Supports info, warn, and error levels.
  • Ease of Integration: Easily implement the ILogger interface with your preferred logging libraries.

Installation

Install via npm:

npm install @wroud/api-logger

Install via yarn:

yarn add @wroud/api-logger

Documentation

For detailed usage and API reference, visit the documentation site.

Example

// Import the ILogger interface
import { ILogger } from "@wroud/api-logger";

// Implement the ILogger interface
class ConsoleLogger implements ILogger {
  info(...messages: any[]): void {
    console.info(...messages);
  }

  warn(...messages: any[]): void {
    console.warn(...messages);
  }

  error(...messages: any[]): void {
    console.error(...messages);
  }
}

// Usage example
const logger: ILogger = new ConsoleLogger();

logger.info("This is an info message");
logger.warn("This is a warning message");
logger.error("This is an error message");

Integrating with @wroud/di

If you're using @wroud/di for dependency injection, you can easily inject your logger implementation:

import { ServiceContainerBuilder, injectable } from "@wroud/di";
import { ILogger } from "@wroud/api-logger";

@injectable()
class ConsoleLogger implements ILogger {
  info(...messages: any[]): void {
    console.info(...messages);
  }

  warn(...messages: any[]): void {
    console.warn(...messages);
  }

  error(...messages: any[]): void {
    console.error(...messages);
  }
}

const builder = new ServiceContainerBuilder();
builder.addSingleton(ConsoleLogger);
const provider = builder.build();

const logger = provider.getService(ConsoleLogger);
logger.info("Hello world with DI!");

Changelog

All notable changes to this project will be documented in the CHANGELOG file.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Package Sidebar

Install

npm i @wroud/api-logger

Weekly Downloads

0

Version

0.1.1

License

none

Unpacked Size

6.02 kB

Total Files

9

Last publish

Collaborators

  • wroud