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