1 | |
---|---|
2 | #ifndef AWS_COMMON_LOG_CHANNEL_H |
3 | #define AWS_COMMON_LOG_CHANNEL_H |
4 | |
5 | /* |
6 | * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"). |
9 | * You may not use this file except in compliance with the License. |
10 | * A copy of the License is located at |
11 | * |
12 | * http://aws.amazon.com/apache2.0 |
13 | * |
14 | * or in the "license" file accompanying this file. This file is distributed |
15 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
16 | * express or implied. See the License for the specific language governing |
17 | * permissions and limitations under the License. |
18 | */ |
19 | |
20 | #include <aws/common/common.h> |
21 | |
22 | #include <aws/common/logging.h> |
23 | |
24 | struct aws_string; |
25 | struct aws_log_writer; |
26 | |
27 | /* |
28 | * Log channel interface and default implementations |
29 | * |
30 | * A log channel is an abstraction for the transfer of formatted log data between a source (formatter) |
31 | * and a sink (writer). |
32 | */ |
33 | struct aws_log_channel; |
34 | |
35 | typedef int(aws_log_channel_send_fn)(struct aws_log_channel *channel, struct aws_string *output); |
36 | typedef void(aws_log_channel_clean_up_fn)(struct aws_log_channel *channel); |
37 | |
38 | struct aws_log_channel_vtable { |
39 | aws_log_channel_send_fn *send; |
40 | aws_log_channel_clean_up_fn *clean_up; |
41 | }; |
42 | |
43 | struct aws_log_channel { |
44 | struct aws_log_channel_vtable *vtable; |
45 | struct aws_allocator *allocator; |
46 | struct aws_log_writer *writer; |
47 | void *impl; |
48 | }; |
49 | |
50 | AWS_EXTERN_C_BEGIN |
51 | |
52 | /* |
53 | * Simple channel that results in log lines being written in the same thread they were generated in. |
54 | * |
55 | * The passed in log writer is not an ownership transfer. The log channel does not clean up the writer. |
56 | */ |
57 | AWS_COMMON_API |
58 | int aws_log_channel_init_foreground( |
59 | struct aws_log_channel *channel, |
60 | struct aws_allocator *allocator, |
61 | struct aws_log_writer *writer); |
62 | |
63 | /* |
64 | * Simple channel that sends log lines to a background thread. |
65 | * |
66 | * The passed in log writer is not an ownership transfer. The log channel does not clean up the writer. |
67 | */ |
68 | AWS_COMMON_API |
69 | int aws_log_channel_init_background( |
70 | struct aws_log_channel *channel, |
71 | struct aws_allocator *allocator, |
72 | struct aws_log_writer *writer); |
73 | |
74 | /* |
75 | * Channel cleanup function |
76 | */ |
77 | AWS_COMMON_API |
78 | void aws_log_channel_clean_up(struct aws_log_channel *channel); |
79 | |
80 | AWS_EXTERN_C_END |
81 | |
82 | #endif /* AWS_COMMON_LOG_CHANNEL_H */ |
83 |