ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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.

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)
void log_mmap_destroy (void)
 Shutdown mmap logging.

Detailed Description

Logging utility stubs for WASM.

Definition in file 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 wasm/stubs/log.c.

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

◆ log_mmap_destroy()

void log_mmap_destroy ( void )

Shutdown mmap logging.

Syncs and unmaps the log file.

Definition at line 73 of file wasm/stubs/log.c.

73 {
74 // No-op - mmap logging not used in WASM
75}

◆ 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 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 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:50

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 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 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 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 wasm/stubs/log.c.

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

◆ terminal_choose_log_fd()

int terminal_choose_log_fd ( log_level_t level)

Definition at line 63 of file wasm/stubs/log.c.

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