ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
logging.c File Reference

📝 Multi-level logging with terminal color support, file rotation, and async output More...

Go to the source code of this file.

Data Structures

struct  log_context_t
 

Macros

#define LOG_COLOR_COUNT   7 /* DEV, DEBUG, INFO, WARN, ERROR, FATAL, RESET */
 
#define LOGGING_INTERNAL_ERROR(error, message, ...)
 

Enumerations

enum  log_color_mode_t { LOG_CMODE_16 = 0 , LOG_CMODE_256 = 1 , LOG_CMODE_TRUECOLOR = 2 , LOG_CMODE_COUNT = 3 }
 

Functions

size_t get_current_time_formatted (char *time_buf)
 Get current time as formatted string.
 
char * format_message (const char *format, va_list args)
 Format a message using va_list.
 
void log_init (const char *filename, log_level_t level, bool force_stderr, bool use_mmap)
 Initialize the logging system.
 
void log_destroy (void)
 Destroy the logging system and close log file.
 
void log_set_level (log_level_t level)
 Set the minimum log level.
 
log_level_t log_get_level (void)
 Get the current minimum log level.
 
void log_set_terminal_output (bool enabled)
 Control stderr output to terminal.
 
bool log_get_terminal_output (void)
 Get current terminal output setting.
 
void log_set_force_stderr (bool enabled)
 Force all terminal log output to stderr.
 
bool log_get_force_stderr (void)
 Get current force_stderr setting.
 
bool log_lock_terminal (void)
 Lock terminal output for exclusive access by the calling thread.
 
void log_unlock_terminal (bool previous_state)
 Release terminal lock and flush buffered messages.
 
void log_set_flush_delay (unsigned int delay_ms)
 Set the delay between flushing buffered log entries.
 
void log_truncate_if_large (void)
 Manually truncate large log files.
 
void log_msg (log_level_t level, const char *file, int line, const char *func, const char *fmt,...)
 Log a message at a specific level.
 
void log_plain_msg (const char *fmt,...)
 Plain logging without timestamps or levels.
 
void log_plain_stderr_msg (const char *fmt,...)
 Plain logging to stderr with newline.
 
void log_plain_stderr_nonewline_msg (const char *fmt,...)
 Plain logging to stderr without trailing newline.
 
void log_file_msg (const char *fmt,...)
 Log to file only, no stderr output.
 
asciichat_error_t log_network_message (socket_t sockfd, const struct crypto_context_t *crypto_ctx, log_level_t level, remote_log_direction_t direction, const char *fmt,...)
 Send a formatted log message over the network.
 
asciichat_error_t log_net_message (socket_t sockfd, const struct crypto_context_t *crypto_ctx, log_level_t level, remote_log_direction_t direction, const char *file, int line, const char *func, const char *fmt,...)
 Log a message to all destinations (network, file, and terminal).
 
void log_redetect_terminal_capabilities (void)
 Re-detect terminal capabilities after logging is initialized.
 
const char ** log_get_color_array (void)
 Get the appropriate color array based on terminal capabilities.
 
const char * log_level_color (log_color_t color)
 Get color string for a given color enum.
 
asciichat_error_t log_enable_mmap (const char *log_path)
 Enable lock-free mmap-based logging.
 
asciichat_error_t log_enable_mmap_sized (const char *log_path, size_t max_size)
 Enable lock-free mmap logging with custom file size.
 
void log_disable_mmap (void)
 Disable mmap logging and return to mutex-based logging.
 
void log_shutdown_begin (void)
 Begin shutdown phase - disable console logging but keep file logging.
 
void log_shutdown_end (void)
 End shutdown phase - restore previous logging settings.
 

Detailed Description

📝 Multi-level logging with terminal color support, file rotation, and async output

Definition in file log/logging.c.

Macro Definition Documentation

◆ LOG_COLOR_COUNT

#define LOG_COLOR_COUNT   7 /* DEV, DEBUG, INFO, WARN, ERROR, FATAL, RESET */

Definition at line 77 of file log/logging.c.

◆ LOGGING_INTERNAL_ERROR

#define LOGGING_INTERNAL_ERROR (   error,
  message,
  ... 
)
Value:
do { \
asciichat_set_errno_with_message(error, __FILE__, __LINE__, __func__, message, ##__VA_ARGS__); \
static const char *msg_header = "CRITICAL LOGGING SYSTEM ERROR: "; \
safe_fprintf(stderr, "%s%s%s: %s", log_level_color(LOG_COLOR_ERROR), msg_header, log_level_color(LOG_COLOR_RESET), \
message); \
platform_write(g_log.file, msg_header, strlen(msg_header)); \
platform_write(g_log.file, message, strlen(message)); \
platform_write(g_log.file, "\n", 1); \
platform_print_backtrace(0); \
} while (0)
const char * log_level_color(log_color_t color)
Get color string for a given color enum.
@ LOG_COLOR_RESET
@ LOG_COLOR_ERROR

Definition at line 104 of file log/logging.c.

105 { \
106 asciichat_set_errno_with_message(error, __FILE__, __LINE__, __func__, message, ##__VA_ARGS__); \
107 static const char *msg_header = "CRITICAL LOGGING SYSTEM ERROR: "; \
108 safe_fprintf(stderr, "%s%s%s: %s", log_level_color(LOG_COLOR_ERROR), msg_header, log_level_color(LOG_COLOR_RESET), \
109 message); \
110 platform_write(g_log.file, msg_header, strlen(msg_header)); \
111 platform_write(g_log.file, message, strlen(message)); \
112 platform_write(g_log.file, "\n", 1); \
113 platform_print_backtrace(0); \
114 } while (0)

Enumeration Type Documentation

◆ log_color_mode_t

Enumerator
LOG_CMODE_16 
LOG_CMODE_256 
LOG_CMODE_TRUECOLOR 
LOG_CMODE_COUNT 

Definition at line 75 of file log/logging.c.

log_color_mode_t
Definition log/logging.c:75
@ LOG_CMODE_256
Definition log/logging.c:75
@ LOG_CMODE_TRUECOLOR
Definition log/logging.c:75
@ LOG_CMODE_16
Definition log/logging.c:75
@ LOG_CMODE_COUNT
Definition log/logging.c:75