Debian Codegraph @

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

raw symbols SCIP
1
2 #ifndef AWS_COMMON_LOG_WRITER_H
3 #define AWS_COMMON_LOG_WRITER_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 AWS_PUSH_SANE_WARNING_LEVEL
13
14 struct aws_allocator;
15 struct aws_string;
16
17 /*
18 * Log writer interface and default implementation(s)
19 *
20 * A log writer functions as a sink for formatted log lines. We provide
21 * default implementations that go to stdout, stderr, and a specified file.
22 */
23 struct aws_log_writer;
24
25 typedef int(aws_log_writer_write_fn)(struct aws_log_writer *writer, const struct aws_string *output);
26 typedef void(aws_log_writer_clean_up_fn)(struct aws_log_writer *writer);
27
28 struct aws_log_writer_vtable {
29 aws_log_writer_write_fn *write;
30 aws_log_writer_clean_up_fn *clean_up;
31 };
32
33 struct aws_log_writer {
34 struct aws_log_writer_vtable *vtable;
35 struct aws_allocator *allocator;
36 void *impl;
37 };
38
39 struct aws_log_writer_file_options {
40 const char *filename;
41 FILE *file;
42 };
43
44 AWS_EXTERN_C_BEGIN
45
46 /*
47 * Initialize a log writer that sends log lines to stdout. Uses C library IO.
48 */
49 AWS_COMMON_API
50 int aws_log_writer_init_stdout(struct aws_log_writer *writer, struct aws_allocator *allocator);
51
52 /*
53 * Initialize a log writer that sends log lines to stderr. Uses C library IO.
54 */
55 AWS_COMMON_API
56 int aws_log_writer_init_stderr(struct aws_log_writer *writer, struct aws_allocator *allocator);
57
58 /*
59 * Initialize a log writer that sends log lines to a file. Uses C library IO.
60 */
61 AWS_COMMON_API
62 int aws_log_writer_init_file(
63 struct aws_log_writer *writer,
64 struct aws_allocator *allocator,
65 struct aws_log_writer_file_options *options);
66
67 /*
68 * Frees all resources used by a log writer with the exception of the base structure memory
69 */
70 AWS_COMMON_API
71 void aws_log_writer_clean_up(struct aws_log_writer *writer);
72
73 AWS_EXTERN_C_END
74 AWS_POP_SANE_WARNING_LEVEL
75
76 #endif /* AWS_COMMON_LOG_WRITER_H */