Skip to content

Commit

Permalink
Documented static variables and added links to them
Browse files Browse the repository at this point in the history
* Static variables are now documented, showing the internal workings of 
the Message Logger module;
* The other text documentation now adequately link to the Message 
Logger's internal variables;
  • Loading branch information
AndreLaranjeira committed Nov 12, 2021
1 parent 0e2d322 commit 1bd16e2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
58 changes: 33 additions & 25 deletions include/message_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,15 @@ int get_time_format(TimeFormat *time_format_destination);
//! \param message_category Category of message whose display colors are being
//! set.
//! \param assigned_colors Pointer to the display colors being copied to a
//! message category of the Message Logger's LoggerColorPallet.
//! message category of the \link #logger_color_pallet Message Logger's
//! color pallet. \endlink
//! \return Returns 0 when successfully executed and -1 if an error occurs.
//!
//! This function sets the display colors for a given #MessageCategory in the
//! Message Logger's LoggerColorPallet. This is done by copying the information
//! from a valid, non-NULL DisplayColors pointer provided by the user to an
//! index of the \link LoggerColorPallet::message_colors message_colors
//! \endlink array.
//! \link #logger_color_pallet Message Logger's color pallet. \endlink This is
//! done by copying the information from a valid, non-NULL DisplayColors
//! pointer provided by the user to an index of the \link
//! LoggerColorPallet::message_colors message_colors \endlink array.
//!
//! If an error occurs when setting the display colors, this function will
//! return -1 and the Message Logger will print an error message explaining
Expand All @@ -444,13 +445,15 @@ int set_logger_msg_colors(
//! category.
//! \param tag_category Category of tag whose display colors are being set.
//! \param assigned_colors Pointer to the display colors being copied to a tag
//! category of the Message Logger's LoggerColorPallet.
//! category of the \link #logger_color_pallet Message Logger's
//! color pallet. \endlink
//! \return Returns 0 when successfully executed and -1 if an error occurs.
//!
//! This function sets the display colors for a given #TagCategory in the
//! Message Logger's LoggerColorPallet. This is done by copying the information
//! from a valid, non-NULL DisplayColors pointer provided by the user to an
//! index of the \link LoggerColorPallet::tag_colors tag_colors \endlink array.
//! This function sets the display colors for a given #TagCategory in the \link
//! #logger_color_pallet Message Logger's color pallet. \endlink This is done
//! by copying the information from a valid, non-NULL DisplayColors pointer
//! provided by the user to an index of the \link LoggerColorPallet::tag_colors
//! tag_colors \endlink array.
//!
//! If an error occurs when setting the display colors, this function will
//! return -1 and the Message Logger will print an error message explaining
Expand All @@ -476,8 +479,9 @@ int set_logger_tag_colors(
//! \return Returns 0 when successfully executed and -1 if an error occurs.
//!
//! This function sets the \link TimeFormat::string_representation
//! string_representation \endlink in the Message Logger's TimeFormat, which is
//! used when saving messages to a log file if one is configured. The time
//! string_representation \endlink in the \link #logger_time_fmt
//! Message Logger's time format. \endlink This format is used when
//! timestamping messages saved to a log file, if one is configured. The time
//! format information is copied from a valid, non-NULL pointer provided by the
//! user.
//!
Expand Down Expand Up @@ -568,8 +572,9 @@ void error(const char *context, const char *format, ...);
void info(const char *context, const char *format, ...);

//! \fn void lock_logger_recursive_mutex()
//! \brief Lock the Message Logger's recursive mutex lock, preventing any
//! other thread from using the Message Logger. Thread safety MUST be enabled.
//! \brief Lock the \link #logger_recursive_mutex Message Logger's recursive
//! mutex lock. \endlink This prevents any other thread from using the Message
//! Logger. Thread safety MUST be enabled.
//!
//! This function locks the recursive mutex lock utilized by the Message Logger
//! to ensure thread safety. When the recursive mutex is locked by a thread,
Expand Down Expand Up @@ -687,16 +692,18 @@ void reset_background_color();
void reset_colors();

//! \fn void reset_logger_colors()
//! \brief Reset the Message Logger's colors to their defaults.
//!
//! This function resets the Message Logger's LoggerColorPallet by setting it's
//! \link LoggerColorPallet::message_colors message_colors \endlink and \link
//! LoggerColorPallet::tag_colors tag_colors \endlink to the default values
//! specifed in the macros #DEFAULT_LOGGER_MESSAGE_COLORS and
//! #DEFAULT_LOGGER_TAG_COLORS. ALL the values are reset, so any changes made
//! with calls to the functions \link set_logger_msg_colors()
//! set_logger_msg_colors \endlink and \link set_logger_tag_colors()
//! set_logger_tag_colors \endlink will be lost after this function is called.
//! \brief Reset the \link #logger_color_pallet Message Logger's color pallet
//! \endlink colors to their defaults.
//!
//! This function resets the \link #logger_color_pallet Message Logger's color
//! pallet \endlink by setting it's \link LoggerColorPallet::message_colors
//! message_colors \endlink and \link LoggerColorPallet::tag_colors tag_colors
//! \endlink to the default values specifed in the macros
//! #DEFAULT_LOGGER_MESSAGE_COLORS and #DEFAULT_LOGGER_TAG_COLORS. ALL the
//! values are reset, so any changes made with calls to the functions
//! \link set_logger_msg_colors() set_logger_msg_colors \endlink and \link
//! set_logger_tag_colors() set_logger_tag_colors \endlink will be lost after
//! this function is called.
//!
//! \par Usage example
//! \code
Expand Down Expand Up @@ -745,7 +752,8 @@ void reset_text_color();
void success(const char *context, const char *format, ...);

//! \fn void unlock_logger_recursive_mutex()
//! \brief Unlock the Message Logger's recursive mutex lock, allowing other
//! \brief Unlock the \link #logger_recursive_mutex Message Logger's recursive
//! mutex lock \endlink, allowing other
//! threads to use the Message Logger if no recursive locks remain. Thread
//! safety MUST be enabled.
//!
Expand Down
13 changes: 11 additions & 2 deletions src/message_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@
#include "message_logger.h"

// Private constants:
//! \brief Default logger color pallet configuration.
const static LoggerColorPallet default_color_pallet = {
.message_colors = DEFAULT_LOGGER_MESSAGE_COLORS,
.tag_colors = DEFAULT_LOGGER_TAG_COLORS
};

// Private variables:

//! \brief Message Logger's file pointer for any configured log file.
static FILE *log_file = NULL;

//! \brief Message Logger's color pallet for messages and tags.
static LoggerColorPallet logger_color_pallet = {
.message_colors = DEFAULT_LOGGER_MESSAGE_COLORS,
.tag_colors = DEFAULT_LOGGER_TAG_COLORS
};

//! \brief Message Logger's recursive mutex used to ensure thread safety.
static pthread_mutex_t *logger_recursive_mutex = NULL;

//! \brief Message Logger's time format for log file timestamps.
static TimeFormat logger_time_fmt = {
.string_representation = "%H:%M:%S %d-%m-%Y"
};
Expand Down Expand Up @@ -276,8 +285,8 @@ static void log_timestamp(FILE* log_file, TimeFormat* time_format);
//! \param context Text containing the message's caller context.
//!
//! This function writes the context tag of a message to the terminal. The
//! colors used for the context tag are taken from the Message Logger's
//! LoggerColorPallet.
//! colors used for the context tag are taken from the \link
//! #logger_color_pallet Message Logger's color pallet. \endlink
//!
//! \par Usage example
//! \code
Expand Down

0 comments on commit 1bd16e2

Please sign in to comment.