Logging Guidelines

Logging Guidelines

This document describes the logging guidelines for the application. Please follow these guidelines when contributing to the project.

DO NOT use console.log() or console.error() in production code. Use the logger instead.

Logger is a wrapper around the console object. It provides a way to log messages with different levels of severity. It also provides a way to log messages to a file.

Usage

Log a message

import logger from "app/utils/logger";
 
// Initialize the logger
const log = logger.getInstance("my-module");
 
log.info("This is an info message");
log.warn("This is a warning message");
log.error("This is an error message");
 
// Log an error with a stack trace
log.error(new Error("This is an error"));
 
// Log an error with a custom message
log.error(new Error("This is an error"), "This is a custom message");
 
// Log a message with a object
log.info("This is a message", { foo: "bar" });

Levels

Use the following levels when logging.

Error

Use the error level when logging an error.

Warn

Use the warn level when logging a warning.

Info

Use the info level when logging information.

Debug

Use the debug level when logging debug information.

Trace

Use the trace level when logging trace information.

Messages

Use the following guidelines when logging messages.

Example

Use the following example when logging.

import { logger } from "@/utils/logging/logger";
 
logger.error("An error occurred.");
logger.warn("A warning occurred.");
logger.info("Some information.");
logger.debug("Some debug information.");
logger.trace("Some trace information.");