|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
Lock-free memory-mapped text logging with crash safety. More...
Go to the source code of this file.
Data Structures | |
| struct | log_mmap_config |
| Configuration for mmap logging. More... | |
Macros | |
| #define | LOG_MMAP_DEFAULT_SIZE (4 * 1024 * 1024) |
| Default mmap log file size (4MB) | |
Typedefs | |
| typedef struct log_mmap_config | log_mmap_config_t |
| Configuration for mmap logging. | |
Functions | |
| asciichat_error_t | log_mmap_init (const log_mmap_config_t *config) |
| Initialize mmap-based text logging. | |
| asciichat_error_t | log_mmap_init_simple (const char *log_path, size_t max_size) |
| Initialize mmap logging with simple parameters. | |
| void | log_mmap_destroy (void) |
| Shutdown mmap logging. | |
| void | log_mmap_write (int level, const char *file, int line, const char *func, const char *fmt,...) |
| Write a log entry directly to the mmap'd file (lock-free) | |
| bool | log_mmap_is_active (void) |
| Check if mmap logging is active. | |
| void | log_mmap_sync (void) |
| Force sync the mmap'd file to disk. | |
| void | log_mmap_install_crash_handlers (void) |
| Install signal handlers for crash safety. | |
| void | log_mmap_get_stats (uint64_t *bytes_written, uint64_t *wrap_count) |
| Get statistics about the mmap log. | |
| bool | log_mmap_get_usage (size_t *used, size_t *capacity) |
| Get current mmap log usage. | |
| void | log_mmap_rotate (void) |
| Rotate the mmap log (tail-keeping rotation) | |
Lock-free memory-mapped text logging with crash safety.
This module provides crash-safe logging by writing human-readable text directly to a memory-mapped log file. Key features:
Usage:
Definition in file log/mmap.h.
| #define LOG_MMAP_DEFAULT_SIZE (4 * 1024 * 1024) |
Default mmap log file size (4MB)
Definition at line 46 of file log/mmap.h.
| typedef struct log_mmap_config log_mmap_config_t |
Configuration for mmap logging.
| void log_mmap_destroy | ( | void | ) |
Shutdown mmap logging.
Syncs and unmaps the log file.
Definition at line 257 of file mmap.c.
References log_info, log_mmap_write(), platform_mmap_close(), and platform_mmap_sync().
Referenced by log_destroy(), log_disable_mmap(), and log_mmap_init().
Get statistics about the mmap log.
| [out] | bytes_written | Total bytes written since init |
| [out] | wrap_count | Number of times log has wrapped |
Definition at line 385 of file mmap.c.
References bytes_written, and wrap_count.
| bool log_mmap_get_usage | ( | size_t * | used, |
| size_t * | capacity | ||
| ) |
Get current mmap log usage.
| [out] | used | Current bytes used in the log |
| [out] | capacity | Total capacity of the log |
Definition at line 394 of file mmap.c.
| asciichat_error_t log_mmap_init | ( | const log_mmap_config_t * | config | ) |
Initialize mmap-based text logging.
Creates or opens a memory-mapped log file. Text is written directly to the file, so it's readable even after a crash.
| config | Configuration options |
Definition at line 188 of file mmap.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, log_info, LOG_MMAP_DEFAULT_SIZE, log_mmap_destroy(), log_mmap_install_crash_handlers(), log_mmap_write(), log_mmap_config::log_path, log_warn, log_mmap_config::max_size, platform_mmap_init(), platform_mmap_open(), SAFE_STRNCPY, and SET_ERRNO.
Referenced by log_mmap_init_simple().
| asciichat_error_t log_mmap_init_simple | ( | const char * | log_path, |
| size_t | max_size | ||
| ) |
Initialize mmap logging with simple parameters.
Convenience wrapper around log_mmap_init().
| log_path | Path to log file |
| max_size | Maximum file size (0 = default 4MB) |
Definition at line 249 of file mmap.c.
References log_mmap_init(), and log_mmap_config::log_path.
Referenced by log_enable_mmap_sized(), and log_init().
| void log_mmap_install_crash_handlers | ( | void | ) |
Install signal handlers for crash safety.
Registers handlers for SIGSEGV, SIGABRT, etc. that sync the mmap before the process terminates.
Definition at line 141 of file mmap.c.
Referenced by log_mmap_init().
| bool log_mmap_is_active | ( | void | ) |
Check if mmap logging is active.
Definition at line 375 of file mmap.c.
Referenced by log_destroy(), log_disable_mmap(), log_file_msg(), log_msg(), and log_plain_msg().
| void log_mmap_rotate | ( | void | ) |
Rotate the mmap log (tail-keeping rotation)
Keeps the most recent log entries (tail) and discards old ones. This is the mmap equivalent of file-based log rotation.
Definition at line 408 of file mmap.c.
References platform_mmap_sync().
| void log_mmap_sync | ( | void | ) |
Force sync the mmap'd file to disk.
Ensures all written data is flushed to the underlying file. Called automatically for ERROR/FATAL levels and on shutdown.
Definition at line 379 of file mmap.c.
References platform_mmap_sync().
| void log_mmap_write | ( | int | level, |
| const char * | file, | ||
| int | line, | ||
| const char * | func, | ||
| const char * | fmt, | ||
| ... | |||
| ) |
Write a log entry directly to the mmap'd file (lock-free)
Formats the log message and writes it directly as human-readable text. Uses atomic operations only, no mutex.
| level | Log level |
| file | Source file (can be NULL) |
| line | Source line |
| func | Function name (can be NULL) |
| fmt | Format string |
| ... | Format arguments |
Definition at line 309 of file mmap.c.
References LOG_MMAP_MSG_BUFFER_SIZE, LOG_TIMESTAMP_BUFFER_SIZE, and platform_mmap_sync().
Referenced by log_file_msg(), log_mmap_destroy(), log_mmap_init(), log_msg(), and log_plain_msg().