ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
options/registry/logging.c
Go to the documentation of this file.
1
12
13#include <options/registry/common.h>
14#include <options/registry/metadata.h>
15#include <options/registry/mode_defaults.h>
16#include <options/parsers.h>
17
18// ============================================================================
19// LOGGING CATEGORY - Binary-level logging options
20// ============================================================================
21static const int default_stats_interval = 0;
22static const char default_otel_log_level[] = "info";
23static const char default_otel_enabled_telemetry[] = "traces,logs,metrics";
24static const double default_otel_realtime_sample_rate = 0.01;
25static const int default_otel_realtime_max_per_second = 10;
26static const int default_otel_metrics_interval = 10000;
27static const int default_otel_timeout = 5000;
28static const int default_otel_queue_capacity = 4096;
30 {"otel-log-level",
31 '\0',
33 offsetof(options_t, otel_log_level),
34 default_otel_log_level,
35 sizeof(((options_t *)0)->otel_log_level),
36 "Minimum exported log level: dev,debug,info,warn,error,fatal.",
37 "OTEL",
38 "LEVEL",
39 false,
40 "ASCII_CHAT_OTEL_LOG_LEVEL",
41 NULL,
42 NULL,
43 false,
44 false,
46 {.input_type = OPTION_INPUT_STRING},
47 NULL},
48 {"otel-endpoint",
49 '\0',
51 offsetof(options_t, otel_endpoint),
53 sizeof(((options_t *)0)->otel_endpoint),
54 "Collector base URL; enables telemetry. OTEL_EXPORTER_OTLP_PROTOCOL selects http/protobuf or grpc.",
55 "OTEL",
56 "VALUE",
57 false,
58 "ASCII_CHAT_OTEL_ENDPOINT",
59 NULL,
60 NULL,
61 false,
62 false,
64 {.input_type = OPTION_INPUT_STRING},
65 NULL},
66 {"otel-ca-file",
67 '\0',
69 offsetof(options_t, otel_ca_file),
70 NULL,
71 sizeof(((options_t *)0)->otel_ca_file),
72 "PEM CA bundle for HTTPS telemetry; replaces system roots.",
73 "OTEL",
74 "VALUE",
75 false,
76 "ASCII_CHAT_OTEL_CA_FILE",
77 NULL,
78 NULL,
79 false,
80 false,
82 {.input_type = OPTION_INPUT_STRING},
83 NULL},
84 {"otel-enabled-telemetry",
85 '\0',
87 offsetof(options_t, otel_enabled_telemetry),
88 default_otel_enabled_telemetry,
89 sizeof(((options_t *)0)->otel_enabled_telemetry),
90 "Comma-separated traces,logs,metrics, or none.",
91 "OTEL",
92 "VALUE",
93 false,
94 "ASCII_CHAT_OTEL_ENABLED_TELEMETRY",
95 NULL,
96 NULL,
97 false,
98 false,
100 {.input_type = OPTION_INPUT_STRING},
101 NULL},
102 {"otel-realtime-sample-rate",
103 '\0',
105 offsetof(options_t, otel_realtime_sample_rate),
106 &default_otel_realtime_sample_rate,
107 sizeof(((options_t *)0)->otel_realtime_sample_rate),
108 "Sampling probability for frame/audio/packet operations (0..1).",
109 "OTEL",
110 "VALUE",
111 false,
112 "ASCII_CHAT_OTEL_REALTIME_SAMPLE_RATE",
113 NULL,
114 NULL,
115 false,
116 false,
118 {.numeric_range = {0, 1, 0}, .input_type = OPTION_INPUT_NUMERIC},
119 NULL},
120 {"otel-realtime-max-per-second",
121 '\0',
123 offsetof(options_t, otel_realtime_max_per_second),
124 &default_otel_realtime_max_per_second,
125 sizeof(((options_t *)0)->otel_realtime_max_per_second),
126 "Maximum sampled realtime root operations per process per second.",
127 "OTEL",
128 "VALUE",
129 false,
130 "ASCII_CHAT_OTEL_REALTIME_MAX_PER_SECOND",
131 NULL,
132 NULL,
133 false,
134 false,
136 {.numeric_range = {1, 1048576, 1}, .input_type = OPTION_INPUT_NUMERIC},
137 NULL},
138 {"otel-metrics-interval",
139 '\0',
141 offsetof(options_t, otel_metrics_interval),
142 &default_otel_metrics_interval,
143 sizeof(((options_t *)0)->otel_metrics_interval),
144 "Metrics export interval in milliseconds.",
145 "OTEL",
146 "VALUE",
147 false,
148 "ASCII_CHAT_OTEL_METRICS_INTERVAL",
149 NULL,
150 NULL,
151 false,
152 false,
154 {.numeric_range = {1, 1048576, 1}, .input_type = OPTION_INPUT_NUMERIC},
155 NULL},
156 {"otel-timeout",
157 '\0',
159 offsetof(options_t, otel_timeout),
160 &default_otel_timeout,
161 sizeof(((options_t *)0)->otel_timeout),
162 "Export timeout in milliseconds; shutdown flush is capped at 400 ms.",
163 "OTEL",
164 "VALUE",
165 false,
166 "ASCII_CHAT_OTEL_TIMEOUT",
167 NULL,
168 NULL,
169 false,
170 false,
172 {.numeric_range = {1, 1048576, 1}, .input_type = OPTION_INPUT_NUMERIC},
173 NULL},
174 {"otel-queue-capacity",
175 '\0',
177 offsetof(options_t, otel_queue_capacity),
178 &default_otel_queue_capacity,
179 sizeof(((options_t *)0)->otel_queue_capacity),
180 "Bounded exporter queue capacity (power of two).",
181 "OTEL",
182 "VALUE",
183 false,
184 "ASCII_CHAT_OTEL_QUEUE_CAPACITY",
185 NULL,
186 NULL,
187 false,
188 false,
190 {.numeric_range = {1, 1048576, 1}, .input_type = OPTION_INPUT_NUMERIC},
191 NULL},
192
193 {"stats-interval",
194 '\0',
196 offsetof(options_t, stats_interval),
197 &default_stats_interval,
198 sizeof(int),
199 "Write plain statistics to stdout (stderr for MCP) every N seconds (0 disables). Press = for live statistics.",
200 "LOGGING",
201 "SECONDS",
202 false,
203 "ASCII_CHAT_STATS_INTERVAL",
204 NULL,
205 NULL,
206 false,
207 false,
209 {.numeric_range = {0, 86400, 1}, .input_type = OPTION_INPUT_NUMERIC},
210 NULL},
211 // LOGGING GROUP (binary-level)
212 {"log-file",
213 'L',
215 offsetof(options_t, log_file),
216 NULL, // Use mode_default_getter instead
217 0,
218#ifndef NDEBUG
219 "Set FILE as path for log file (default: current directory; filenames: server.log, client.log, mirror.log, "
220 "acds.log, discovery.log).",
221#else
222 "Set FILE as path for log file (default: $TMPDIR/ascii-chat/ or %TEMP%\\ascii-chat\\; filenames: server.log, "
223 "client.log, mirror.log, acds.log, discovery.log).",
224#endif
225 "LOGGING",
226 "FILE",
227 false,
228 "ASCII_CHAT_LOG_FILE",
229 NULL,
231 false,
232 false,
233#ifndef NDEBUG
235#else
237#endif
238 {0},
240 {"log-level",
241 '\0',
243 offsetof(options_t, log_level),
244 &default_log_level_value,
245 sizeof(log_level_t),
246 "Set log level: dev, debug, info, warn, error, fatal. Logs at or above this level are written.",
247 "LOGGING",
248 NULL,
249 false,
250 "ASCII_CHAT_LOG_LEVEL",
251 NULL,
253 false,
254 false,
256 {.enum_values = g_log_level_values, .enum_descriptions = g_log_level_descs, .enum_integer_values = g_log_level_integers, .input_type = OPTION_INPUT_ENUM},
257 NULL},
258 {"verbose",
259 'V',
261 offsetof(options_t, verbose_level),
262 0,
263 sizeof(unsigned short int),
264 "Increase log verbosity (stackable: -VV, -VVV).",
265 "LOGGING",
266 NULL,
267 false,
268 "ASCII_CHAT_VERBOSE",
269 NULL,
271 false,
272 true,
274 {0},
275 NULL},
276 {"quiet",
277 'q',
279 offsetof(options_t, quiet),
280 &default_quiet_value,
281 sizeof(bool),
282 "Disable console logging (log to file only).",
283 "LOGGING",
284 NULL,
285 false,
286 "ASCII_CHAT_QUIET",
287 NULL,
288 NULL,
289 false,
290 false,
292 {0},
293 NULL},
294 {"grep",
295 '\0',
297 offsetof(options_t, grep_pattern),
298 NULL, // Default is empty string - not meaningful to display in help
299 sizeof(char *),
300 "Filter console logs with perl compatible regular expressions or fixed strings. "
301 "Format 1: /pattern/flags (with flags). Format 2: pattern (plain regex, no flags). "
302 "Flags (format 1 only): i(case-insensitive), m(multiline), s(dotall), x(extended), g(global highlight), "
303 "I(invert match), F(fixed string), A<n>(n lines after), B<n>(n lines before), C<n>(n lines of context). "
304 "Multiple --grep allowed (OR).",
305 "LOGGING",
306 "PATTERN",
307 false,
308 "ASCII_CHAT_GREP",
309 NULL,
310 NULL,
311 false,
312 false,
314 {.examples = (const char *[]){"ERROR", "client\\.c", "network.*failed", NULL}},
315 NULL},
316 {"color-scheme",
317 '\0',
319 offsetof(options_t, color_scheme_name),
321 sizeof(((options_t *)0)->color_scheme_name),
322 "Color scheme for logging output. Built-in schemes: pastel, nord, solarized, dracula, gruvbox, "
323 "monokai, base16-default. All schemes with light variants auto-adapt to terminal background.",
324 "LOGGING",
325 "NAME",
326 false,
327 "ASCII_CHAT_COLOR_SCHEME",
328 NULL,
329 NULL,
330 false,
331 false,
333 {.input_type = OPTION_INPUT_STRING},
334 NULL},
335 {"json",
336 '\0',
338 offsetof(options_t, json),
339 &default_json_value,
340 sizeof(bool),
341 "Enable JSON logging (machine-readable NDJSON format). Disabled by default (text format).",
342 "LOGGING",
343 NULL,
344 false,
345 "ASCII_CHAT_JSON",
346 NULL,
347 NULL,
348 false,
349 false,
351 {0},
352 NULL},
353 {"log-template",
354 '\0',
356 offsetof(options_t, log_template),
357 NULL,
358 sizeof(((options_t *)0)->log_template),
359 "Custom log format string. Format specifiers: %time(fmt) - time with strftime format (see man 3 strftime); "
360 "%level - log level (DEV/DEBUG/INFO/WARN/ERROR/FATAL); %level_aligned - level padded to 5 chars; "
361 "%file - full file path; %file_relative - file path relative to project root; %line - line number; "
362 "%func - function name; %tid - thread ID; %message - log message; "
363 "%color(LEVEL, text) - colorize text using LEVEL's color from current scheme. "
364 "Escape %% for literal %, \\\\ for literal backslash.",
365 "LOGGING",
366 "TEMPLATE",
367 false,
368 "ASCII_CHAT_LOG_TEMPLATE",
369 NULL,
370 NULL,
371 false,
372 false,
374 {.input_type = OPTION_INPUT_STRING},
375 NULL},
376 {"log-format-console",
377 '\0',
379 offsetof(options_t, log_format_console_only),
380 NULL,
381 sizeof(bool),
382 "Apply custom log template (--log-template) only to console output (file logs use default format). See "
383 "--log-template "
384 "for supported format specifiers.",
385 "LOGGING",
386 NULL,
387 false,
388 "ASCII_CHAT_LOG_FORMAT_CONSOLE",
389 NULL,
390 NULL,
391 false,
392 false,
394 {0},
395 NULL},
396
@ OPTION_INPUT_STRING
Free-form text input.
Definition builder.h:189
@ OPTION_INPUT_NUMERIC
Numeric value with optional min/max/step.
Definition builder.h:188
@ OPTION_INPUT_ENUM
Choose from fixed set of enum values.
Definition builder.h:187
@ OPTION_TYPE_INT
Integer value (–count 42).
Definition builder.h:172
@ OPTION_TYPE_DOUBLE
Floating point (–ratio 1.5).
Definition builder.h:174
@ OPTION_TYPE_STRING
String value (–name foo).
Definition builder.h:173
@ OPTION_TYPE_CALLBACK
Custom parser function.
Definition builder.h:175
@ OPTION_TYPE_BOOL
Boolean flag (–flag, no value).
Definition builder.h:171
log_level_t
Logging levels enumeration.
Definition types.h:33
#define log_file(...)
File-only logging - writes to log file only, no stderr output.
Definition log/log.h:687
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
#define OPT_OTEL_ENDPOINT_DEFAULT
Debug and Dev builds export to the local Spaniel Compose collector.
Definition options.h:349
#define OPT_COLOR_SCHEME_NAME_DEFAULT
Default color scheme name (pastel).
Definition options.h:365
@ OPTION_MODE_BINARY
Binary-level options (parsed before mode detection).
Definition options.h:942
@ OPTION_MODE_CLIENT
Client mode (bit 1).
Definition options.h:936
@ OPTION_MODE_DISCOVERY
Discovery mode (bit 4).
Definition options.h:939
@ OPTION_MODE_SERVER
Server mode (bit 0).
Definition options.h:935
@ OPTION_MODE_MIRROR
Mirror mode (bit 2).
Definition options.h:937
@ OPTION_MODE_MCP_SERVER
Definition options.h:940
@ OPTION_MODE_DISCOVERY_SVC
Discovery server mode (bit 3).
Definition options.h:938
const registry_entry_t g_logging_entries[]
#define REGISTRY_TERMINATOR()
Initialize a terminator entry (sentinel value for array end) Uses designated initializers to properly...
const char * g_log_level_descs[]
Definition metadata.c:25
const int g_log_level_integers[]
Definition metadata.c:24
const char * g_log_level_values[]
Definition metadata.c:23
const void * get_default_log_file(asciichat_mode_t mode)
Get mode-specific default value for –log-file.
bool parse_verbose_flag(const char *arg, void *dest, char **error_msg)
Custom parser for –verbose flag.
Definition parsers.c:900
bool parse_log_file(const char *arg, void *dest, char **error_msg)
Custom parser for log file paths (–log-file, -L).
Definition parsers.c:1055
bool parse_log_level(const char *arg, void *dest, char **error_msg)
Parse log level option.
Definition parsers.c:383
Custom option parsers for enum types.
Registry entry - stores option definition with mode bitmask and metadata.