file-error-logging

Configuration

The file-error-logging library allows you to configure various aspects of logging to suit your needs. You can set the configuration using the setConfig method.

Configuration Options

logsDir

rotation

development

Example

Here’s an example of how to configure the logger:

import Logger from "file-error-logging";

// Configure the logger
Logger.setConfig({
  logsDir: "./custom-logs",
  rotation: "monthly",
  development: true,
});

Adding Custom Log Levels

You can add custom log levels with their own color, timestamping, and file logging rules using the addLogLevel method.

addLogLevel Parameters

Example

import Logger from "file-error-logging/dist/cjs";

// Add a new custom log level
Logger.addLogLevel("debug", {
  color: "green",
  includeTimestampInConsole: true,
  logToFile: true,
  logFileName: "debug.log",
  onTrigger: (message) => {
    reportToAPI(message);
  },
});

// Log a message with the custom log level
Logger.log("debug", "This is a debug message");

Logging Messages

You can log messages at different levels using the log method. You can also override the default options for each log message.

log Parameters

Example

import Logger from "file-error-logging";

// Log messages with different levels
Logger.log("info", "This is an info message", {
  includeTimestampInConsole: true,
  logToFile: true,
  color: "whiteBright",
});
Logger.log("warn", "This is a warning message", {
  onTrigger: (message) => {
    reportToAPI(message);
  },
});
Logger.log("verb", "This is a verbose message");
Logger.log("error", new Error("This is an error message"));