2.0.11 • Published 2 years ago

@kalbekalu/logger v2.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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.

2.0.11

2 years ago

2.0.10

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago