1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
use {
crate::{AwsCAllocator, AwsCString, AwsDateFormat, AWS_C_COMMON_PACKAGE_ID},
std::ffi::c_void,
};
pub const AWS_LOG_LEVEL_NONE: isize = 0;
pub const AWS_LOG_LEVEL_FATAL: isize = 1;
pub const AWS_LOG_LEVEL_ERROR: isize = 2;
pub const AWS_LOG_LEVEL_WARN: isize = 3;
pub const AWS_LOG_LEVEL_INFO: isize = 4;
pub const AWS_LOG_LEVEL_DEBUG: isize = 5;
pub const AWS_LOG_LEVEL_TRACE: isize = 6;
#[repr(C)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AwsLogLevel {
AWS_LL_NONE = AWS_LOG_LEVEL_NONE,
AWS_LL_FATAL = AWS_LOG_LEVEL_FATAL,
AWS_LL_ERROR = AWS_LOG_LEVEL_ERROR,
AWS_LL_WARN = AWS_LOG_LEVEL_WARN,
AWS_LL_INFO = AWS_LOG_LEVEL_INFO,
AWS_LL_DEBUG = AWS_LOG_LEVEL_DEBUG,
AWS_LL_TRACE = AWS_LOG_LEVEL_TRACE,
AWS_LL_COUNT,
}
pub type AwsLogSubject = u32;
pub const AWS_LOG_SUBJECT_STRIDE_BITS: usize = 10;
pub const AWS_LOG_SUBJECT_STRIDE: isize = 1 << AWS_LOG_SUBJECT_STRIDE_BITS;
pub const fn aws_log_subject_begin_range(x: isize) -> isize {
x * AWS_LOG_SUBJECT_STRIDE
}
pub const fn aws_log_subject_end_range(x: isize) -> isize {
(x + 1) * AWS_LOG_SUBJECT_STRIDE - 1
}
#[repr(C)]
pub struct AwsCLogSubjectInfo {
pub subject_id: AwsLogSubject,
pub subject_name: *const u8,
pub subject_description: *const u8,
}
#[repr(C)]
pub struct AwsCLogSubjectInfoList {
pub subject_list: *const AwsCLogSubjectInfo,
pub count: usize,
}
#[repr(C)]
#[allow(non_camel_case_types)]
pub enum AwsCommonLogSubject {
AWS_LS_COMMON_GENERAL = aws_log_subject_begin_range(AWS_C_COMMON_PACKAGE_ID),
AWS_LS_COMMON_TASK_SCHEDULER,
AWS_LS_COMMON_THREAD,
AWS_LS_COMMON_MEMTRACE,
AWS_LS_COMMON_XML_PARSER,
AWS_LS_COMMON_IO,
AWS_LS_COMMON_BUS,
AWS_LS_COMMON_TEST,
AWS_LS_COMMON_JSON_PARSER,
AWS_LS_COMMON_LAST = aws_log_subject_end_range(AWS_C_COMMON_PACKAGE_ID),
}
#[repr(C)]
pub struct AwsCLoggerVtable {
pub log: *const extern "C" fn(*const AwsCLogger, AwsLogLevel, AwsLogSubject, *const u8, ...) -> i32,
pub get_log_level: *const extern "C" fn(*const AwsCLogger, AwsLogSubject) -> AwsLogLevel,
pub clean_up: *const extern "C" fn(*const AwsCLogger),
pub set_log_level: *const extern "C" fn(*const AwsCLogger, AwsLogLevel) -> i32,
}
#[repr(C)]
pub struct AwsCLogger {
vtable: *const AwsCLoggerVtable,
allocator: *const AwsCAllocator,
p_impl: *mut c_void,
}
#[repr(C)]
pub struct AwsCLoggerStandardOptions {
pub level: AwsLogLevel,
pub filename: *const u8,
pub file: *mut libc::FILE,
}
#[repr(C)]
pub struct AwsLogWriterVtable {
pub write: *const extern "C" fn(writer: *const AwsCLogWriter, output: *const AwsCString) -> i32,
pub clean_up: *const extern "C" fn(writer: *const AwsCLogWriter),
}
#[repr(C)]
pub struct AwsCLogChannelVtable {
pub send: *const extern "C" fn(channel: *const AwsCLogChannel, output: *const AwsCString) -> i32,
pub clean_up: *const extern "C" fn(channel: *const AwsCLogChannel),
}
#[repr(C)]
pub struct AwsCLogChannel {
pub vtable: *const AwsCLogChannelVtable,
pub allocator: *const AwsCAllocator,
pub writer: *const AwsCLogWriter,
pub r#impl: *mut c_void,
}
#[repr(C)]
pub struct AwsCLogFormatterVtable {
pub format: *const extern "C" fn(
formatter: *const AwsCLogFormatter,
formatted_output: *const *mut AwsCString,
level: AwsLogLevel,
subject: AwsLogSubject,
format: *const u8,
args: *mut c_void,
) -> i32,
pub clean_up: *const extern "C" fn(formatter: *const AwsCLogFormatter),
}
#[repr(C)]
pub struct AwsCLogFormatter {
pub vtable: *const AwsCLogFormatterVtable,
pub allocator: *const AwsCAllocator,
pub r#impl: *mut c_void,
}
#[repr(C)]
pub struct AwsLogFormatterStandardOptions {
pub date_format: AwsDateFormat,
}
#[repr(C)]
pub struct AwsCLoggingStandardFormattingData {
pub log_line_format: *mut u8,
pub total_length: usize,
pub level: AwsLogLevel,
pub suject_name: *const u8,
pub format: *const u8,
pub date_format: AwsDateFormat,
pub allocator: *const AwsCAllocator,
pub amount_written: usize,
}
#[repr(C)]
pub struct AwsCLogWriter {
pub vtable: *const AwsLogWriterVtable,
pub allocator: *const AwsCAllocator,
pub r#impl: *mut c_void,
}
#[repr(C)]
pub struct AwsCLogWriterFileOptions {
pub filename: *const u8,
pub file: *mut libc::FILE,
}
#[link(name = "aws-c-common")]
extern "C" {
pub fn aws_logger_set(logger: *const AwsCLogger);
pub fn aws_logger_get() -> *const AwsCLogger;
pub fn aws_logger_get_conditional(subject: AwsLogSubject, level: AwsLogLevel) -> *const AwsCLogger;
pub fn aws_logger_clean_up(logger: *const AwsCLogger);
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_logger_set_log_level(logger: *const AwsCLogger, level: AwsLogLevel) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_level_to_string(log_level: AwsLogLevel, level_string: *mut *const u8) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_string_to_log_level(level_string: *const u8, log_level: *mut AwsLogLevel) -> i32;
pub fn aws_log_subject_name(subject: AwsLogSubject) -> *const u8;
pub fn aws_register_log_subject_info_list(log_subject_list: *const AwsCLogSubjectInfoList);
pub fn aws_unregister_log_subject_info_list(log_subject_list: *const AwsCLogSubjectInfoList);
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_logger_init_standard(
logger: *const AwsCLogger,
allocator: *const AwsCAllocator,
options: *const AwsCLoggerStandardOptions,
) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_logger_init_from_external(
logger: *const AwsCLogger,
allocator: *const AwsCAllocator,
formatter: *const AwsCLogFormatter,
channel: *const AwsCLogChannel,
writer: *const AwsCLogWriter,
level: AwsLogLevel,
) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_logger_init_noalloc(
logger: *const AwsCLogger,
allocator: *const AwsCAllocator,
options: *const AwsCLoggerStandardOptions,
) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_channel_init_foreground(
channel: *const AwsCLogChannel,
allocator: *const AwsCAllocator,
writer: *const AwsCLogWriter,
) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_channel_init_background(
channel: *const AwsCLogChannel,
allocator: *const AwsCAllocator,
writer: *const AwsCLogWriter,
) -> i32;
pub fn aws_log_channel_clean_up(channel: *const AwsCLogChannel);
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_formatter_init_default(
formatter: *const AwsCLogFormatter,
allocator: *const AwsCAllocator,
options: *const AwsLogFormatterStandardOptions,
) -> i32;
pub fn aws_log_formatter_clean_up(formatter: *const AwsCLogFormatter);
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_format_standard_log_line(
formatting_data: *mut AwsCLoggingStandardFormattingData,
args: *mut c_void,
) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_writer_init_stdout(writer: *const AwsCLogWriter, allocator: *const AwsCAllocator) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_writer_init_stderr(writer: *const AwsCLogWriter, allocator: *const AwsCAllocator) -> i32;
#[must_use = "returns an i32 that contains a result code (AWS_OP_SUCCESS or AWS_OP_ERR)"]
pub fn aws_log_writer_init_file(
writer: *const AwsCLogWriter,
allocator: *const AwsCAllocator,
options: *const AwsCLogWriterFileOptions,
) -> i32;
pub fn aws_log_writer_clean_up(writer: *const AwsCLogWriter);
}