Debug

This header provides a simple logging utility with three severity levels: LOG, WARN, and FAULT. Each log entry prints the filename and line number, followed by the severity level and the provided message. In addition, each severity level has its own color to make it visually distinct in the console.

Usage:

To use this logging utility, simply include the header and use the macros:

  1. LOG: For standard informational logs.

  2. WARN: For warning logs which could potentially cause problems.

  3. FAULT: For errors that need immediate attention.

Example:

#include "your_logging_header_name.h"

int main() {
    LOG("This is a standard log.");
    WARN("This is a warning.");
    FAULT("This is an error log.");

    return 0;
}

Explanation:

  • ANSI_COLOR_XXXXX: These are ANSI color codes which are used to change the text color in terminals that support it.

  • LOG, WARN, FAULT Macros: These are convenience macros for logging. They automatically capture and pass the current line number and filename to the corresponding logging functions.

  • log, warn, fault Functions: These are variadic templates that can take any number of arguments and log them. This allows you to log messages with mixed types, like:

  • LOG("The value of x is:", x);

Note:

Keep in mind that not all terminals support ANSI color codes, so on some systems, these logs might not appear colored. Also, consider using more advanced logging libraries (like spdlog, glog, etc.) for larger projects, as they offer many more features, better performance, and broader compatibility.

Last updated