Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Log_Manager Class Reference

Thread-safe log manager with timestamps. More...

#include <log.H>

Public Member Functions

 Log_Manager (FILE *_file_descriptor)
 Construct log manager for a file.
 
 ~Log_Manager ()
 Destructor releases mutex.
 
void init_line (const char *format,...)
 Write log line without newline (for multi-part messages).
 
void write_line (const char *format,...)
 Write complete log line with newline.
 

Private Member Functions

void get_time ()
 Get current time as formatted string.
 

Private Attributes

FILEfile_descriptor
 Output file descriptor.
 
pthread_mutex_t mutex
 Thread synchronization mutex.
 
char print_buffer [Max_Log_Line_Length]
 Message buffer.
 
char time_buffer [Max_Time_Line_Length]
 Timestamp buffer.
 
size_t num_lines
 Lines written (not used)
 
size_t max_num_lines
 Max lines (not used)
 

Static Private Attributes

static const short int Max_Log_Line_Length = 512
 Max message length.
 
static const short int Max_Time_Line_Length = 61
 Max timestamp length.
 

Detailed Description

Thread-safe log manager with timestamps.

Provides synchronized logging to a file descriptor with automatic timestamp generation and optional debug information.

Thread Safety

All logging operations are protected by a mutex, making it safe for concurrent use from multiple threads.

Log Format

Definition at line 91 of file log.H.

Constructor & Destructor Documentation

◆ Log_Manager()

Log_Manager::Log_Manager ( FILE _file_descriptor)
inline

Construct log manager for a file.

Parameters
_file_descriptorOutput file (e.g., stdout, stderr, or fopen result)

Definition at line 130 of file log.H.

References init_mutex(), Aleph::maps(), and mutex.

◆ ~Log_Manager()

Log_Manager::~Log_Manager ( )
inline

Destructor releases mutex.

Definition at line 139 of file log.H.

References destroy_mutex(), and mutex.

Member Function Documentation

◆ get_time()

void Log_Manager::get_time ( )
inlineprivate

Get current time as formatted string.

Formats time as: "Weekday Month Day Year HH:MM:SS AM/PM"

Definition at line 111 of file log.H.

References Aleph::maps(), Max_Time_Line_Length, and time_buffer.

Referenced by init_line(), and write_line().

◆ init_line()

void Log_Manager::init_line ( const char format,
  ... 
)
inline

Write log line without newline (for multi-part messages).

Parameters
formatPrintf-style format string
...Format arguments
Note
In DEBUG mode, also accepts file and line parameters

Definition at line 152 of file log.H.

References CRITICAL_SECTION, file, file_descriptor, get_time(), Aleph::maps(), mutex, and time_buffer.

◆ write_line()

void Log_Manager::write_line ( const char format,
  ... 
)
inline

Write complete log line with newline.

Parameters
formatPrintf-style format string
...Format arguments
Note
In DEBUG mode, also accepts file and line parameters

Definition at line 187 of file log.H.

References CRITICAL_SECTION, file, file_descriptor, get_time(), Aleph::maps(), mutex, and time_buffer.

Member Data Documentation

◆ file_descriptor

FILE* Log_Manager::file_descriptor
private

Output file descriptor.

Definition at line 96 of file log.H.

Referenced by init_line(), and write_line().

◆ Max_Log_Line_Length

const short int Log_Manager::Max_Log_Line_Length = 512
staticprivate

Max message length.

Definition at line 93 of file log.H.

◆ max_num_lines

size_t Log_Manager::max_num_lines
private

Max lines (not used)

Definition at line 104 of file log.H.

◆ Max_Time_Line_Length

const short int Log_Manager::Max_Time_Line_Length = 61
staticprivate

Max timestamp length.

Definition at line 94 of file log.H.

Referenced by get_time().

◆ mutex

pthread_mutex_t Log_Manager::mutex
private

Thread synchronization mutex.

Definition at line 98 of file log.H.

Referenced by Log_Manager(), ~Log_Manager(), init_line(), and write_line().

◆ num_lines

size_t Log_Manager::num_lines
private

Lines written (not used)

Definition at line 103 of file log.H.

◆ print_buffer

char Log_Manager::print_buffer[Max_Log_Line_Length]
private

Message buffer.

Definition at line 100 of file log.H.

◆ time_buffer

char Log_Manager::time_buffer[Max_Time_Line_Length]
private

Timestamp buffer.

Definition at line 101 of file log.H.

Referenced by get_time(), init_line(), and write_line().


The documentation for this class was generated from the following file: