@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.
- 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
, anderror
levels. -
Ease of Integration: Easily implement the
ILogger
interface with your preferred logging libraries.
Install via npm:
npm install @wroud/api-logger
Install via yarn:
yarn add @wroud/api-logger
For detailed usage and API reference, visit the documentation site.
// 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");
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!");
All notable changes to this project will be documented in the CHANGELOG file.
This project is licensed under the MIT License. See the LICENSE file for details.