CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
cdi_logger_api.h
Go to the documentation of this file.
1// -------------------------------------------------------------------------------------------
2// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3// This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License.
4// License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE
5// -------------------------------------------------------------------------------------------
6
13#ifndef CDI_LOGGER_API_API_H__
14#define CDI_LOGGER_API_API_H__
15
16#include <stdbool.h>
17
18#include "cdi_utility_api.h"
19#include "cdi_log_api.h"
20#include "cdi_os_api.h"
21
22//*********************************************************************************************************************
23//***************************************** START OF DEFINITIONS AND TYPES ********************************************
24//*********************************************************************************************************************
25
27#define CDI_MAX_LOG_STRING_LENGTH (1024)
28
30#define CDI_MAX_LOG_FUNCTION_NAME_STRING_LENGTH (128)
31
37
42typedef struct CdiLogState* CdiLogHandle;
43
48
67
76#define CDI_LOG_THREAD(log_level, ...) \
77 CdiLogger(CdiLoggerThreadLogGet(), kLogComponentGeneric, log_level, __FUNCTION__, __LINE__, __VA_ARGS__)
78
89#define CDI_LOG_THREAD_COMPONENT(log_level, component, ...) \
90 CdiLogger(CdiLoggerThreadLogGet(), component, log_level, __FUNCTION__, __LINE__, __VA_ARGS__)
91
99#define CDI_LOG_HANDLE(log_handle, log_level, ...) \
100 CdiLogger(log_handle, kLogComponentGeneric, log_level, __FUNCTION__, __LINE__, __VA_ARGS__)
101
108#define CDI_LOG_THREAD_MULTILINE_BEGIN(log_level, multiline_state_ptr) \
109 CdiLoggerMultilineBegin(CdiLoggerThreadLogGet(), kLogComponentGeneric, log_level, __FUNCTION__, __LINE__, \
110 multiline_state_ptr)
111
116#define CDI_LOG_MULTILINE(multiline_state_ptr, ...) \
117 CdiLoggerMultiline(multiline_state_ptr, __VA_ARGS__)
118
124#define CDI_LOG_MULTILINE_END(multiline_handle) CdiLoggerMultilineEnd(multiline_handle)
125
132#define CDI_LOG_WHEN(log_level, condition, number, ...) \
133 do { \
134 static uint64_t log_event_count = 0; \
135 if (condition) { \
136 CdiOsAtomicInc64(&log_event_count); \
137 if ((number) > 0 && (1 == log_event_count % (number) || 1 == (number))) { \
138 if (1 < (number)) { \
139 CDI_LOG_HANDLE(CdiLogGlobalGet(), kLogInfo, "The following message has " \
140 "occurred [%llu] times.", log_event_count); \
141 } \
142 CdiLogger(CdiLogGlobalGet(), kLogComponentGeneric, log_level, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
143 } \
144 } \
145 } while (0)
146
153#define CDI_LOG_THREAD_WHEN(log_level, condition, number, ...) \
154 do { \
155 static uint64_t log_event_count = 0; \
156 if (condition) { \
157 CdiOsAtomicInc64(&log_event_count); \
158 if ((number) > 0 && (1 == log_event_count % (number) || 1 == (number))) { \
159 if (1 < (number)) { \
160 CDI_LOG_HANDLE(CdiLoggerThreadLogGet(), kLogInfo, "The following message has " \
161 "occurred [%llu] times.", log_event_count); \
162 } \
163 CdiLogger(CdiLoggerThreadLogGet(), kLogComponentGeneric, log_level, \
164 __FUNCTION__, __LINE__, ##__VA_ARGS__); \
165 } \
166 } \
167 } while (0)
168
169//*********************************************************************************************************************
170//******************************************* START OF PUBLIC FUNCTIONS ***********************************************
171//*********************************************************************************************************************
172
177
186CDI_INTERFACE bool CdiLoggerCreate(CdiLogLevel default_log_level, CdiLoggerHandle* ret_logger_handle_ptr);
187
199 const CdiLogMethodData* log_method_data_ptr, CdiLogHandle* ret_log_handle_ptr);
200
210CDI_INTERFACE bool CdiLoggerCreateFileLog(CdiLoggerHandle logger_handle, const char* filename_str,
211 CdiLogHandle* ret_log_handle_ptr);
212
226CDI_INTERFACE void CdiLogger(CdiLogHandle handle, CdiLogComponent component, CdiLogLevel log_level,
227 const char* function_name_str, int line_number, const char* format_str, ...);
228
236
246
252
259
272 const char* function_name_str, int line_number,
273 CdiLogMultilineState* state_ptr);
274
283CDI_INTERFACE void CdiLoggerMultiline(CdiLogMultilineState* state_ptr, const char* format_str, ...);
284
294
302
307
318
323
328
333
338
343
348
355
362
370CDI_INTERFACE void CdiLoggerShutdown(bool force);
371
372#endif // CDI_LOGGER_API_API_H__
CdiReturnStatus
Values used for API function return codes.
Definition cdi_core_api.h:189
This file declares the public API data types, structures and functions that comprise the CDI log API.
CdiLogComponent
This selector determines the SDK component type for logging. Logging for it can be enabled/disabled u...
Definition cdi_log_enums.h:35
CdiLogLevel
This selector determines the log level of messages generated using the CdiLogMessageCallback()....
Definition cdi_log_enums.h:50
CDI_INTERFACE void CdiLoggerThreadLogUnset(void)
Definition logger.c:1032
CDI_INTERFACE bool CdiLoggerCreate(CdiLogLevel default_log_level, CdiLoggerHandle *ret_logger_handle_ptr)
Definition logger.c:748
#define CDI_MAX_LOG_FUNCTION_NAME_STRING_LENGTH
Maximum length of log message function name string used in logger.c.
Definition cdi_logger_api.h:30
CDI_INTERFACE CdiLogHandle CdiLoggerThreadLogGet(void)
Definition logger.c:1039
CDI_INTERFACE void CdiLoggerShutdown(bool force)
Definition logger.c:1230
CDI_INTERFACE bool CdiLoggerCreateFileLog(CdiLoggerHandle logger_handle, const char *filename_str, CdiLogHandle *ret_log_handle_ptr)
Definition logger.c:851
CDI_INTERFACE void CdiLoggerDestroyLog(CdiLogHandle handle)
Definition logger.c:1166
CDI_INTERFACE bool CdiLoggerInitialize(void)
Definition logger.c:676
CDI_INTERFACE bool CdiLoggerIsEnabled(CdiLogHandle handle, CdiLogComponent component, CdiLogLevel log_level)
Definition logger.c:1050
CDI_INTERFACE bool CdiLoggerComponentIsEnabled(CdiLogHandle handle, CdiLogComponent component)
Definition logger.c:1082
CDI_INTERFACE void CdiLoggerMultilineBegin(CdiLogHandle handle, CdiLogComponent component, CdiLogLevel log_level, const char *function_name_str, int line_number, CdiLogMultilineState *state_ptr)
Definition logger.c:884
CDI_INTERFACE void CdiLoggerLogFromCallback(CdiLogHandle handle, const CdiLogMessageCbData *cb_data_ptr)
Definition logger.c:998
CDI_INTERFACE CdiReturnStatus CdiLoggerComponentEnable(CdiLogHandle handle, CdiLogComponent component, bool enable)
Definition logger.c:1069
CDI_INTERFACE CdiReturnStatus CdiLoggerComponentEnableGlobal(CdiLogComponent component, bool enable)
Definition logger.c:1106
CDI_INTERFACE CdiReturnStatus CdiLoggerStderrEnable(bool enable, CdiLogLevel level)
Definition logger.c:1158
struct CdiLoggerState * CdiLoggerHandle
Type used as the handle (pointer to an opaque structure) for a logger instance. Each handle represent...
Definition cdi_logger_api.h:36
CDI_INTERFACE bool CdiLoggerThreadLogSet(CdiLogHandle handle)
Definition logger.c:1024
struct CdiLogState * CdiLogHandle
Type used as the handle (pointer to an opaque structure) for a log. Each handle represents an instanc...
Definition cdi_logger_api.h:42
CDI_INTERFACE void CdiLogger(CdiLogHandle handle, CdiLogComponent component, CdiLogLevel log_level, const char *function_name_str, int line_number, const char *format_str,...)
Definition logger.c:862
CDI_INTERFACE void CdiLoggerFlushAllFileLogs(void)
Definition logger.c:1204
CDI_INTERFACE CdiReturnStatus CdiLoggerLevelSet(CdiLogHandle handle, CdiLogComponent component, CdiLogLevel level)
Definition logger.c:1093
CDI_INTERFACE char * CdiLoggerMultilineGetBuffer(CdiLogMultilineState *state_ptr)
Definition logger.c:961
CDI_INTERFACE bool CdiLoggerCreateLog(CdiLoggerHandle logger_handle, CdiConnectionHandle con_handle, const CdiLogMethodData *log_method_data_ptr, CdiLogHandle *ret_log_handle_ptr)
Definition logger.c:773
CDI_INTERFACE void CdiLoggerDestroyLogger(CdiLoggerHandle logger_handle)
Definition logger.c:1197
CDI_INTERFACE void CdiLoggerMultiline(CdiLogMultilineState *state_ptr, const char *format_str,...)
Definition logger.c:909
CDI_INTERFACE void CdiLoggerMultilineEnd(CdiLogMultilineState *state_ptr)
Definition logger.c:971
CDI_INTERFACE CdiReturnStatus CdiLoggerLevelSetGlobal(CdiLogComponent component, CdiLogLevel level)
Definition logger.c:1132
This file contains the declarations for OS functions for creating/managing/freeing threads,...
The declarations in this header file correspond to the definitions in cdi_utility_api....
#define CDI_INTERFACE
Specify C linkage when compiling as C++ and define API interface export for Windows.
Definition cdi_utility_api.h:34
Structure definition behind the connection handles shared with the user's application program....
Definition private.h:371
A structure of this type is passed as the parameter to CdiLogMessageCallback(). It contains a single ...
Definition cdi_log_api.h:81
A structure of this type is used to configure the type of log method that is being used....
Definition cdi_log_api.h:63
Structure used to hold state data for a multiline log message.
Definition cdi_logger_api.h:52
int line_number
Line number in file where log was called.
Definition cdi_logger_api.h:60
CdiLogLevel log_level
Current log level for log_handle.
Definition cdi_logger_api.h:57
CdiLogHandle log_handle
Handle to log being accessed.
Definition cdi_logger_api.h:54
CdiMultilineLogBufferState * buffer_state_ptr
Pointer to log message buffer structure.
Definition cdi_logger_api.h:63
bool logging_enabled
When true, logging is enabled for this log_handle.
Definition cdi_logger_api.h:53
int line_count
Number of log lines in the log message buffer.
Definition cdi_logger_api.h:62
CdiLogComponent component
Selects the SDK component type for logging.
Definition cdi_logger_api.h:56
bool buffer_used
Buffer was used, so don't generate output when ending using CdiLoggerMultilineEnd().
Definition cdi_logger_api.h:65
Structure used to hold state data for a single log of any type (stdout, callback or file).
Definition logger.c:79
Structure used to hold state data for a single logger.
Definition logger.c:43
Structure used to hold a buffer for a multiline log message.
Definition logger.c:105