ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
log/format.h
Go to the documentation of this file.
1
10
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
27typedef enum {
28 LOG_FORMAT_LITERAL, /* Plain text (no % prefix) */
29 LOG_FORMAT_TIME, /* %time(fmt) - custom time format */
30 LOG_FORMAT_LEVEL, /* %level - log level as string */
31 LOG_FORMAT_LEVEL_ALIGNED, /* %level_aligned - log level padded */
32 LOG_FORMAT_FILE, /* %file - file path */
33 LOG_FORMAT_FILE_RELATIVE, /* %file_relative - file path relative to project root */
34 LOG_FORMAT_LINE, /* %line - line number */
35 LOG_FORMAT_FUNC, /* %func - function name */
36 LOG_FORMAT_TID, /* %tid - thread ID */
37 LOG_FORMAT_TNAME, /* %tname - thread name (from debug registry) */
38 LOG_FORMAT_MESSAGE, /* %message - log message */
39 LOG_FORMAT_COLORLOG_LEVEL, /* %colorlog_level_string_to_color - color code */
40 LOG_FORMAT_COLOR, /* %color(LEVEL, content) - colorize content using LEVEL's color */
41 LOG_FORMAT_COLORED_MESSAGE, /* %colored_message - message with things like filenames and 0x numbers colored */
42 LOG_FORMAT_MICROSECONDS, /* %ms - microseconds component of current time (000000-999999) */
43 LOG_FORMAT_NANOSECONDS, /* %ns - nanoseconds component of current time (000000000-999999999) */
44 LOG_FORMAT_STRFTIME_CODE, /* %H, %M, %S, %A, %B, etc. - strftime format codes */
45 LOG_FORMAT_NEWLINE, /* Platform-aware newline (\n) */
47
48/* ============================================================================
49 * Parsed Format Specifier
50 * ============================================================================ */
51
59typedef struct {
60 log_template_type_t type; /* Type of specifier */
61 char *literal; /* For LOG_FORMAT_LITERAL, the text; for LOG_FORMAT_TIME, the format string */
62 size_t literal_len; /* Length of literal text */
64
65/* ============================================================================
66 * Compiled Log Format
67 * ============================================================================ */
68
72typedef struct {
73 log_format_spec_t *specs; /* Array of parsed specifiers */
74 size_t spec_count; /* Number of specifiers */
75 char *original; /* Original format string (for debugging) */
76 bool console_only; /* If true, apply only to console (not file) */
78
79/* ============================================================================
80 * Public API
81 * ============================================================================ */
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
103log_template_t *log_template_parse(const char *format_str, bool console_only);
104
111
143int log_template_apply(const log_template_t *format, char *buf, size_t buf_size, log_level_t level,
144 const char *timestamp, const char *file, int line, const char *func, uint64_t tid,
145 const char *message, bool use_colors, uint64_t time_nanoseconds);
146
147#ifdef __cplusplus
148}
149#endif
150
unsigned long long uint64_t
Definition common.h:63
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:498
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:332
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:328
log_template_type_t
One literal or conversion token in a compiled log format.
Definition log/format.h:27
@ LOG_FORMAT_LEVEL
Definition log/format.h:30
@ LOG_FORMAT_COLOR
Definition log/format.h:40
@ LOG_FORMAT_NEWLINE
Definition log/format.h:45
@ LOG_FORMAT_FILE_RELATIVE
Definition log/format.h:33
@ LOG_FORMAT_LINE
Definition log/format.h:34
@ LOG_FORMAT_MICROSECONDS
Definition log/format.h:42
@ LOG_FORMAT_TID
Definition log/format.h:36
@ LOG_FORMAT_COLORED_MESSAGE
Definition log/format.h:41
@ LOG_FORMAT_LITERAL
Definition log/format.h:28
@ LOG_FORMAT_COLORLOG_LEVEL
Definition log/format.h:39
@ LOG_FORMAT_MESSAGE
Definition log/format.h:38
@ LOG_FORMAT_TIME
Definition log/format.h:29
@ LOG_FORMAT_LEVEL_ALIGNED
Definition log/format.h:31
@ LOG_FORMAT_FUNC
Definition log/format.h:35
@ LOG_FORMAT_NANOSECONDS
Definition log/format.h:43
@ LOG_FORMAT_TNAME
Definition log/format.h:37
@ LOG_FORMAT_STRFTIME_CODE
Definition log/format.h:44
@ LOG_FORMAT_FILE
Definition log/format.h:32
📝 Logging API with multiple log levels and terminal output control
One literal or conversion token in a compiled log format.
Definition log/format.h:59
log_template_type_t type
Definition log/format.h:60
Compiled log format ready for use in log_template_apply().
Definition log/format.h:72
char * original
Definition log/format.h:75
log_format_spec_t * specs
Definition log/format.h:73
size_t spec_count
Definition log/format.h:74