Skip to content
Aleksander Płomiński edited this page Jun 23, 2025 · 3 revisions

Documentation for the cpplogger_handle struct

General informations about cpplogger_handle struct

The cpplogger_handle structure contains a void* pointer that is needed for the C API to work. Do not attempt to call this pointer. The call may terminate with undefined behavior.

Functions adapted for use with API

Constructor and Destructor

cpplogger_handle* cpplogger_create(bool console_enabled, const char* log_file)

Initializes the logger by opening or creating a log file and writing an initialization message.

Parameters:

  • console_enabled: A boolean flag indicating whether logs should also be printed to the console.

  • log_file: The path to the log file where logs will be stored.

Example:

cpplogger_handle* handle = cpplogger_create(true, "abc.txt");

void cpplogger_destroy(cpplogger_handle* handle)

Closes the log file when the logger instance is destroyed.

Parameters:

  • handle: A handle to the class that should be destroyed

Example:

cpplogger_handle* handle = cpplogger_create(true, "abc.txt");
cpplogger_destroy(handle);

Methods for saving logs

void cpplogger_log(const char* msg, cpplogger_handle handle);

Logs a general message with a timestamp.

Parameters:

  • msg: The log message.

  • handle: A handle to the class whose configuration the method is to be called with.

Example:

cpplogger_handle* handle = cpplogger_create(true, "abc.txt");
cpplogger_log("Hello",handle);

void cpplogger_info(const char* msg, int level, cpplogger_handle handle);

Logs an informational message with a specified importance level.

Parameters:

  • msg: The log message.

  • level: The importance level of the message.

  • handle: A handle to the class whose configuration the method is to be called with.

Example:

cpplogger_handle* handle = cpplogger_create(true, "abc.txt");
cpplogger_info("Hello",1,handle);

void cpplogger_warning(const char* msg, int level, cpplogger_handle handle);

Logs a warning message with a specified importance level.

Parameters:

  • msg: The warning message.

  • level: The importance level of the message.

  • handle: A handle to the class whose configuration the method is to be called with.

Example:

cpplogger_handle* handle = cpplogger_create(true, "abc.txt");
cpplogger_warning("Hello",1,handle);

void cpplogger_error(const char* msg, int level, cpplogger_handle handle);

Logs an error message with a specified importance level.

Parameters:

  • msg: The warning message.

  • level: The importance level of the message.

  • handle: A handle to the class whose configuration the method is to be called with.

Example:

cpplogger_handle* handle = cpplogger_create(true, "abc.txt");
cpplogger_error("Hello",1,handle);

Notes

  • If console_enabled is set to true, logs will be printed to std::cout.

  • All log messages include a timestamp formatted as [ DD:MM:YY HH:MM:SS ].

  • The log file is opened in append mode (std::ios::app), ensuring that new logs are added at the end of the file.

  • Functions: cpplogger_log(), cpplogger_info(), cpplogger_warning(), cpplogger_error() can be shortened to: log(), info(), warning(), error() by using the __use_cpplogger_macros macro