Debian Codegraph @

crt/aws-c-common/include/aws/common/log_formatter.h

raw symbols SCIP
1
2 #ifndef AWS_COMMON_LOG_FORMATTER_H
3 #define AWS_COMMON_LOG_FORMATTER_H
4
5 /**
6 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7 * SPDX-License-Identifier: Apache-2.0.
8 */
9
10 #include <aws/common/common.h>
11
12 #include <aws/common/date_time.h>
13 #include <aws/common/logging.h>
14
15 #include <stdarg.h>
16 #include <stdio.h>
17
18 AWS_PUSH_SANE_WARNING_LEVEL
19
20 struct aws_allocator;
21 struct aws_string;
22
23 /*
24 * Log formatter interface and default implementation
25 *
26 * Log formatters are invoked by the LOGF_* macros to transform a set of arguments into
27 * one or more lines of text to be output to a logging sink (writer).
28 */
29 struct aws_log_formatter;
30
31 typedef int(aws_log_formatter_format_fn)(
32 struct aws_log_formatter *formatter,
33 struct aws_string **formatted_output,
34 enum aws_log_level level,
35 aws_log_subject_t subject,
36 const char *format,
37 va_list args);
38
39 typedef void(aws_log_formatter_clean_up_fn)(struct aws_log_formatter *logger);
40
41 struct aws_log_formatter_vtable {
42 aws_log_formatter_format_fn *format;
43 aws_log_formatter_clean_up_fn *clean_up;
44 };
45
46 struct aws_log_formatter {
47 struct aws_log_formatter_vtable *vtable;
48 struct aws_allocator *allocator;
49 void *impl;
50 };
51
52 struct aws_log_formatter_standard_options {
53 enum aws_date_format date_format;
54 };
55
56 struct aws_logging_standard_formatting_data {
57 char *log_line_buffer;
58 size_t total_length;
59 enum aws_log_level level;
60 const char *subject_name;
61 const char *format;
62 enum aws_date_format date_format;
63 struct aws_allocator *allocator; /* not used, just there to make byte_bufs valid */
64
65 size_t amount_written;
66 };
67
68 AWS_EXTERN_C_BEGIN
69
70 /*
71 * Initializes the default log formatter which outputs lines in the format:
72 *
73 * [<LogLevel>] [<Timestamp>] [<ThreadId>] - <User content>\n
74 */
75 AWS_COMMON_API
76 int aws_log_formatter_init_default(
77 struct aws_log_formatter *formatter,
78 struct aws_allocator *allocator,
79 struct aws_log_formatter_standard_options *options);
80
81 /*
82 * Cleans up a log formatter (minus the base structure memory) by calling the formatter's clean_up function
83 * via the vtable.
84 */
85 AWS_COMMON_API
86 void aws_log_formatter_clean_up(struct aws_log_formatter *formatter);
87
88 /*
89 * Formats a single log line based on the input + the var args list. Output is written to a fixed-size
90 * buffer supplied in the data struct.
91 */
92 AWS_COMMON_API
93 int aws_format_standard_log_line(struct aws_logging_standard_formatting_data *formatting_data, va_list args);
94
95 AWS_EXTERN_C_END
96 AWS_POP_SANE_WARNING_LEVEL
97
98 #endif /* AWS_COMMON_LOG_FORMATTER_H */