ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
log/format.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <stdint.h>
14#include <stddef.h>
15#include <stdbool.h>
16#include <ascii-chat/log/log.h>
17
18/* ============================================================================
19 * Format Specifier Types
20 * ============================================================================ */
21
25typedef enum {
26 LOG_FORMAT_LITERAL, /* Plain text (no % prefix) */
27 LOG_FORMAT_TIME, /* %time(fmt) - custom time format */
28 LOG_FORMAT_LEVEL, /* %level - log level as string */
29 LOG_FORMAT_LEVEL_ALIGNED, /* %level_aligned - log level padded */
30 LOG_FORMAT_FILE, /* %file - file path */
31 LOG_FORMAT_FILE_RELATIVE, /* %file_relative - file path relative to project root */
32 LOG_FORMAT_LINE, /* %line - line number */
33 LOG_FORMAT_FUNC, /* %func - function name */
34 LOG_FORMAT_TID, /* %tid - thread ID */
35 LOG_FORMAT_TNAME, /* %tname - thread name (from debug registry) */
36 LOG_FORMAT_MESSAGE, /* %message - log message */
37 LOG_FORMAT_COLORLOG_LEVEL, /* %colorlog_level_string_to_color - color code */
38 LOG_FORMAT_COLOR, /* %color(LEVEL, content) - colorize content using LEVEL's color */
39 LOG_FORMAT_COLORED_MESSAGE, /* %colored_message - message with things like filenames and 0x numbers colored */
40 LOG_FORMAT_MICROSECONDS, /* %ms - microseconds component of current time (000000-999999) */
41 LOG_FORMAT_NANOSECONDS, /* %ns - nanoseconds component of current time (000000000-999999999) */
42 LOG_FORMAT_STRFTIME_CODE, /* %H, %M, %S, %A, %B, etc. - strftime format codes */
43 LOG_FORMAT_NEWLINE, /* Platform-aware newline (\n) */
45
46/* ============================================================================
47 * Parsed Format Specifier
48 * ============================================================================ */
49
53typedef struct {
54 log_template_type_t type; /* Type of specifier */
55 char *literal; /* For LOG_FORMAT_LITERAL, the text; for LOG_FORMAT_TIME, the format string */
56 size_t literal_len; /* Length of literal text */
58
59/* ============================================================================
60 * Compiled Log Format
61 * ============================================================================ */
62
66typedef struct {
67 log_format_spec_t *specs; /* Array of parsed specifiers */
68 size_t spec_count; /* Number of specifiers */
69 char *original; /* Original format string (for debugging) */
70 bool console_only; /* If true, apply only to console (not file) */
72
73/* ============================================================================
74 * Public API
75 * ============================================================================ */
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
97log_template_t *log_template_parse(const char *format_str, bool console_only);
98
105
137int log_template_apply(const log_template_t *format, char *buf, size_t buf_size, log_level_t level,
138 const char *timestamp, const char *file, int line, const char *func, uint64_t tid,
139 const char *message, bool use_colors, uint64_t time_nanoseconds);
140
141#ifdef __cplusplus
142}
143#endif
144
unsigned long long uint64_t
Definition common.h:59
int log_template_apply(const log_template_t *format, char *buf, size_t buf_size, log_level_t level, const char *timestamp, const char *file, int line, const char *func, uint64_t tid, const char *message, bool use_colors, uint64_t time_nanoseconds)
Apply format to a log entry and write result to buffer.
Definition log/format.c:491
log_level_t
Logging levels enumeration.
Definition types.h:29
void log_template_free(log_template_t *format)
Free compiled format structure.
Definition log/format.c:325
log_template_t * log_template_parse(const char *format_str, bool console_only)
Parse a format string into compiled format structure.
Definition log/format.c:321
log_template_type_t
Types of format specifiers that can appear in a format string.
Definition log/format.h:25
@ LOG_FORMAT_LEVEL
Definition log/format.h:28
@ LOG_FORMAT_COLOR
Definition log/format.h:38
@ LOG_FORMAT_NEWLINE
Definition log/format.h:43
@ LOG_FORMAT_FILE_RELATIVE
Definition log/format.h:31
@ LOG_FORMAT_LINE
Definition log/format.h:32
@ LOG_FORMAT_MICROSECONDS
Definition log/format.h:40
@ LOG_FORMAT_TID
Definition log/format.h:34
@ LOG_FORMAT_COLORED_MESSAGE
Definition log/format.h:39
@ LOG_FORMAT_LITERAL
Definition log/format.h:26
@ LOG_FORMAT_COLORLOG_LEVEL
Definition log/format.h:37
@ LOG_FORMAT_MESSAGE
Definition log/format.h:36
@ LOG_FORMAT_TIME
Definition log/format.h:27
@ LOG_FORMAT_LEVEL_ALIGNED
Definition log/format.h:29
@ LOG_FORMAT_FUNC
Definition log/format.h:33
@ LOG_FORMAT_NANOSECONDS
Definition log/format.h:41
@ LOG_FORMAT_TNAME
Definition log/format.h:35
@ LOG_FORMAT_STRFTIME_CODE
Definition log/format.h:42
@ LOG_FORMAT_FILE
Definition log/format.h:30
📝 Logging API with multiple log levels and terminal output control
ClangTool/LibTooling compatibility shim for stdbool.h.
A single parsed format specifier.
Definition log/format.h:53
log_template_type_t type
Definition log/format.h:54
Compiled log format ready for use in log_template_apply()
Definition log/format.h:66
char * original
Definition log/format.h:69
log_format_spec_t * specs
Definition log/format.h:67
size_t spec_count
Definition log/format.h:68