Socket
Book a DemoInstallSign in
Socket

@wroud/api-logger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wroud/api-logger

@wroud/api-logger is a lightweight, TypeScript-compatible logging interface for JavaScript applications. It provides standardized logging methods (`info`, `warn`, `error`) to ensure consistent and maintainable logging across your projects. Designed as an

latest
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

@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.

Keywords

logger

FAQs

Package last updated on 07 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts