@kalbekalu/logger
TypeScript icon, indicating that this package has built-in type declarations

2.0.11 • Public • Published

Logger README

A simple logging utility for Node.js applications, designed to log messages to various destinations, including a remote API endpoint, console, and a local log file.

Installation

npm install @kalbekalu/logger

Usage

Importing the Logger

import Logger from "./Logger";

Creating an instance of Logger

const logger = new Logger(appInfo);
  • appInfo (any): Additional information about the application (e.g., name, version) to include in each log entry.

Logging to a Remote API Endpoint

logger.logToUrl(level, logData, config);
  • level (string): Log level (TRACE, INFO, DEBUG, WARN, ERROR, FATAL).
  • logData (Record<string, any>): Additional data to be logged - can be any valid record object - Required.
  • config (AxiosRequestConfig, optional): Additional Axios configuration options for the API request.

Logging to Console

logger.standard(level, logData);
  • level (string): Log level (TRACE, INFO, DEBUG, WARN, ERROR, FATAL) - Required.
  • logData (Record<string, any>): Additional data to be logged - can be any valid record object - Required.

Logging to a Local File

logger.file(level, logData, logFilePath);
  • level (string): Log level (TRACE, INFO, DEBUG, WARN, ERROR, FATAL) - Required.
  • logData (Record<string, any>): Additional data to be logged - can be any valid record object - Required.
  • logFilePath (string, optional, default: "./app.log"): Path to the local log file - Required.

Example

const logger = new Logger({
  appName: "MyApp",
  appVersion: "1.0.0",
});

logger
  .logToUrl("INFO", { message: "Application started" })
  .then((response) => console.log("Log sent successfully"))
  .catch((error) => console.error("Error sending log:", error));

logger.standard("DEBUG", { message: "Debugging information" });

logger.file("ERROR", { message: "An error occurred" }, "./errors.log");

In this example, logs are sent to a remote API endpoint, printed to the console, and appended to a local log file.

License

This code is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i @kalbekalu/logger

Weekly Downloads

0

Version

2.0.11

License

MIT

Unpacked Size

20.2 kB

Total Files

9

Last publish

Collaborators

  • kalbekalu