ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
log.c File Reference

Logging utility stubs for WASM. More...

Go to the source code of this file.

Typedefs

typedef struct session_log_buffer session_log_buffer_t
 

Functions

asciichat_error_t log_mmap_init_simple (const char *log_path, size_t max_size)
 Initialize mmap logging with simple parameters.
 
bool log_mmap_is_active (void)
 Check if mmap logging is active.
 
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_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)
 
void server_status_log_append (const char *message)
 
void log_json_write (int fd, int level, uint64_t time_ns, const char *file, int line, const char *func, const char *json_msg)
 
int terminal_choose_log_fd (log_level_t level)
 Choose output file descriptor for logging based on level and interactivity.
 
session_log_buffer_t * session_log_buffer_create (void)
 Create a new session log buffer instance.
 
void session_log_buffer_destroy (session_log_buffer_t *buf)
 Cleanup session log buffer instance.
 
void session_log_buffer_clear (session_log_buffer_t *buf)
 Clear all log entries from buffer.
 
void session_log_buffer_append (session_log_buffer_t *buf, const char *message)
 Append a log message to the buffer.
 
size_t session_log_buffer_get_recent (session_log_buffer_t *buf, session_log_entry_t *out_entries, size_t max_count)
 Get recent log entries from buffer.
 
void log_mmap_destroy (void)
 Shutdown mmap logging.
 

Detailed Description

Logging utility stubs for WASM.

Definition in file platform/wasm/stubs/log.c.

Typedef Documentation

◆ session_log_buffer_t

Definition at line 77 of file platform/wasm/stubs/log.c.

Function Documentation

◆ log_json_write()

void log_json_write ( int  fd,
int  level,
uint64_t  time_ns,
const char *  file,
int  line,
const char *  func,
const char *  json_msg 
)

Definition at line 51 of file platform/wasm/stubs/log.c.

52 {
53 (void)fd;
54 (void)level;
55 (void)time_ns;
56 (void)file;
57 (void)line;
58 (void)func;
59 (void)json_msg;
60 // No-op - JSON logging in WASM uses console output instead
61}

◆ log_mmap_destroy()

void log_mmap_destroy ( void  )

Shutdown mmap logging.

Syncs and unmaps the log file.

Definition at line 106 of file platform/wasm/stubs/log.c.

106 {
107 // No-op - mmap logging not used in WASM
108}

◆ log_mmap_get_usage()

bool log_mmap_get_usage ( size_t *  used,
size_t *  capacity 
)

Get current mmap log usage.

Parameters
[out]usedCurrent bytes used in the log
[out]capacityTotal capacity of the log
Returns
true if mmap is active and values are valid

Definition at line 32 of file platform/wasm/stubs/log.c.

32 {
33 if (used)
34 *used = 0;
35 if (capacity)
36 *capacity = 0;
37 return false;
38}

◆ 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().

Parameters
log_pathPath to log file
max_sizeMaximum file size (0 = default 4MB)
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 13 of file platform/wasm/stubs/log.c.

13 {
14 (void)log_path;
15 (void)max_size;
16 return ASCIICHAT_OK; // No-op - mmap logging not supported in WASM
17}
@ ASCIICHAT_OK
Definition error_codes.h:51

References ASCIICHAT_OK.

◆ log_mmap_is_active()

bool log_mmap_is_active ( void  )

Check if mmap logging is active.

Returns
true if mmap logging is initialized and active

Definition at line 19 of file platform/wasm/stubs/log.c.

19 {
20 return false; // mmap logging not active in WASM
21}

◆ log_mmap_rotate()

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.

Note
Caller must hold the rotation mutex from logging.c. This is called by maybe_rotate_log() which handles locking.

Definition at line 40 of file platform/wasm/stubs/log.c.

40 {
41 // No-op
42}

◆ log_mmap_write()

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.

Parameters
levelLog level
fileSource file (can be NULL)
lineSource line
funcFunction name (can be NULL)
fmtFormat string
...Format arguments

Definition at line 23 of file platform/wasm/stubs/log.c.

23 {
24 (void)level;
25 (void)file;
26 (void)line;
27 (void)func;
28 (void)fmt;
29 // No-op - mmap logging not supported in WASM
30}

◆ server_status_log_append()

void server_status_log_append ( const char *  message)

Definition at line 45 of file platform/wasm/stubs/log.c.

45 {
46 (void)message;
47 // No-op - server status screen not used in WASM mirror mode
48}

◆ session_log_buffer_append()

void session_log_buffer_append ( session_log_buffer_t *  buf,
const char *  message 
)

Append a log message to the buffer.

Thread-safe. Called from logging system to capture messages. Message is copied into circular buffer (oldest entry overwritten if full).

Parameters
bufBuffer instance (must not be NULL)
messageLog message text (already formatted with colors)

Definition at line 93 of file platform/wasm/stubs/log.c.

93 {
94 (void)buf;
95 (void)message;
96 // No-op - session log buffer not used in WASM
97}

◆ session_log_buffer_clear()

void session_log_buffer_clear ( session_log_buffer_t *  buf)

Clear all log entries from buffer.

Thread-safe. Resets buffer to empty state, discarding all captured logs. Useful for clearing initialization logs before screen starts rendering.

Parameters
bufBuffer instance (must not be NULL)

Definition at line 88 of file platform/wasm/stubs/log.c.

88 {
89 (void)buf;
90 // No-op - session log buffer not used in WASM
91}

Referenced by terminal_screen_log_clear().

◆ session_log_buffer_create()

session_log_buffer_t * session_log_buffer_create ( void  )

Create a new session log buffer instance.

Allocates and initializes a circular buffer for log capture. Caller is responsible for calling session_log_buffer_destroy() when done.

Returns
Pointer to new buffer instance, or NULL on allocation failure

Definition at line 79 of file platform/wasm/stubs/log.c.

79 {
80 return NULL; // No-op - session log buffer not used in WASM
81}

Referenced by terminal_screen_log_init().

◆ session_log_buffer_destroy()

void session_log_buffer_destroy ( session_log_buffer_t *  buf)

Cleanup session log buffer instance.

Frees the buffer and all internal resources. Safe to call with NULL.

Parameters
bufBuffer instance to destroy (can be NULL)

Definition at line 83 of file platform/wasm/stubs/log.c.

83 {
84 (void)buf;
85 // No-op - session log buffer not used in WASM
86}

Referenced by terminal_screen_log_destroy().

◆ session_log_buffer_get_recent()

size_t session_log_buffer_get_recent ( session_log_buffer_t *  buf,
session_log_entry_t *  out_entries,
size_t  max_count 
)

Get recent log entries from buffer.

Thread-safe. Copies up to max_count recent entries into out_entries. Entries are returned in chronological order (oldest first).

Parameters
bufBuffer instance (must not be NULL)
out_entriesOutput array to fill with log entries
max_countMaximum number of entries to return
Returns
Number of entries actually copied (may be less than max_count)

Definition at line 99 of file platform/wasm/stubs/log.c.

99 {
100 (void)buf;
101 (void)out_entries;
102 (void)max_count;
103 return 0; // No entries in WASM
104}

Referenced by log_search_gather_and_filter_logs(), and terminal_screen_render().

◆ terminal_choose_log_fd()

int terminal_choose_log_fd ( log_level_t  level)

Choose output file descriptor for logging based on level and interactivity.

Parameters
levelLog level (determines default routing: WARN+ to stderr, others to stdout)
Returns
STDERR_FILENO or STDOUT_FILENO based on log level and terminal state

Routes logs appropriately:

  • When terminal is NOT interactive (piped): ALL logs to stderr
  • When force_stderr enabled: ALL logs to stderr
  • Otherwise: WARN/ERROR/FATAL to stderr, others to stdout

This consolidates log routing logic used throughout the codebase.

Note
Use: int fd = terminal_choose_log_fd(LOG_INFO);
Common usage: platform_write_all(terminal_choose_log_fd(level), data, len);

Definition at line 64 of file platform/wasm/stubs/log.c.

64 {
65 // Route based on level: INFO and below go to stdout, WARN and above go to stderr
66 // This matches the native implementation and allows Emscripten to route to
67 // console.log for INFO/DEBUG/DEV and console.error for WARN/ERROR/FATAL
68 if (level >= 3) { // LOG_WARN = 3, LOG_ERROR = 4, LOG_FATAL = 5
69 return 2; // STDERR_FILENO
70 }
71 return 1; // STDOUT_FILENO (LOG_DEV=0, LOG_DEBUG=1, LOG_INFO=2)
72}