ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
apple.c
Go to the documentation of this file.
1
11
12/* Storage capacities in elements; text buffers include the terminating NUL. */
13#define LOG_APPLE_CLEAN_BUFFER_SIZE 4096
14
15#include <os/log.h>
16#include <string.h>
17#include <ascii-chat/log/log.h>
19
20#define APPLE_LOG_SUBSYSTEM "com.ascii-chat"
21#define APPLE_LOG_CATEGORY "default"
22
23static os_log_t apple_log = NULL;
24
25static os_log_t get_apple_log(void) {
26 if (!apple_log) {
27 apple_log = os_log_create(APPLE_LOG_SUBSYSTEM, APPLE_LOG_CATEGORY);
28 }
29 return apple_log;
30}
31
32static os_log_type_t level_to_os_log_type(log_level_t level) {
33 switch (level) {
34 case LOG_DEV:
35 case LOG_DEBUG:
36 return OS_LOG_TYPE_DEBUG;
37 case LOG_INFO:
38 return OS_LOG_TYPE_INFO;
39 case LOG_WARN:
40 // OS_LOG_TYPE_DEFAULT is the closest to "warning" in os_log;
41 // os_log has no dedicated warning level.
42 return OS_LOG_TYPE_DEFAULT;
43 case LOG_ERROR:
44 return OS_LOG_TYPE_ERROR;
45 case LOG_FATAL:
46 return OS_LOG_TYPE_FAULT;
47 default:
48 return OS_LOG_TYPE_DEFAULT;
49 }
50}
51
52// Platform hook called by the logging system after each message is formatted.
53// The message contains the full formatted log line with ANSI color codes.
54// We strip ANSI codes before sending to os_log for clean output.
55void platform_log_hook(log_level_t level, const char *message) {
56 if (!message) {
57 return;
58 }
59
60 os_log_t log = get_apple_log();
61
62 // Strip ANSI escape codes for clean system log output
64 strip_ansi_codes(message, clean, sizeof(clean));
65
66 os_log_with_type(log, level_to_os_log_type(level), "%{public}s", clean);
67}
#define APPLE_LOG_SUBSYSTEM
Definition apple.c:20
#define APPLE_LOG_CATEGORY
Definition apple.c:21
#define LOG_APPLE_CLEAN_BUFFER_SIZE
Definition apple.c:13
void platform_log_hook(log_level_t level, const char *message)
Definition apple.c:55
log_level_t
Logging levels enumeration.
Definition types.h:29
void strip_ansi_codes(const char *input, char *output, size_t output_size)
Strip ANSI escape codes from a string.
Definition string.c:374
📝 Logging API with multiple log levels and terminal output control
🔤 String Manipulation and Shell Escaping Utilities
#define LOG_DEV
Definition types.h:38
#define LOG_DEBUG
Definition types.h:39
#define LOG_FATAL
Definition types.h:43
#define LOG_ERROR
Definition types.h:42
#define LOG_WARN
Definition types.h:41
#define LOG_INFO
Definition types.h:40