Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
xlogging.h
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #ifndef XLOGGING_H 00005 #define XLOGGING_H 00006 00007 #include "azure_c_shared_utility/agenttime.h" 00008 #include "azure_c_shared_utility/optimize_size.h" 00009 00010 #if defined(ESP8266_RTOS) 00011 #include "c_types.h" 00012 #endif 00013 00014 #if defined(ARDUINO_ARCH_ESP8266) 00015 #include "esp8266/azcpgmspace.h" 00016 #endif 00017 00018 #ifdef __cplusplus 00019 #include <cstdio> 00020 extern "C" { 00021 #else 00022 #include <stdio.h> 00023 #endif /* __cplusplus */ 00024 00025 #ifdef TIZENRT 00026 #undef LOG_INFO 00027 #endif 00028 00029 typedef enum LOG_CATEGORY_TAG 00030 { 00031 AZ_LOG_ERROR, 00032 AZ_LOG_INFO, 00033 AZ_LOG_TRACE 00034 } LOG_CATEGORY; 00035 00036 #if defined _MSC_VER 00037 #define FUNC_NAME __FUNCDNAME__ 00038 #else 00039 #define FUNC_NAME __func__ 00040 #endif 00041 00042 typedef void(*LOGGER_LOG)(LOG_CATEGORY log_category, const char* file, const char* func, int line, unsigned int options, const char* format, ...); 00043 typedef void(*LOGGER_LOG_GETLASTERROR)(const char* file, const char* func, int line, const char* format, ...); 00044 00045 #define TEMP_BUFFER_SIZE 1024 00046 #define MESSAGE_BUFFER_SIZE 260 00047 00048 #define LOG_NONE 0x00 00049 #define LOG_LINE 0x01 00050 00051 /*no logging is useful when time and fprintf are mocked*/ 00052 #ifdef NO_LOGGING 00053 #define LOG(...) 00054 #define LogInfo(...) 00055 #define LogBinary(...) 00056 #define LogError(...) 00057 #define xlogging_get_log_function() NULL 00058 #define xlogging_set_log_function(...) 00059 #define LogErrorWinHTTPWithGetLastErrorAsString(...) 00060 #define UNUSED(x) (void)(x) 00061 #elif (defined MINIMAL_LOGERROR) 00062 #define LOG(...) 00063 #define LogInfo(...) 00064 #define LogBinary(...) 00065 #define LogError(...) printf("error %s: line %d\n",__FILE__,__LINE__); 00066 #define xlogging_get_log_function() NULL 00067 #define xlogging_set_log_function(...) 00068 #define LogErrorWinHTTPWithGetLastErrorAsString(...) 00069 #define UNUSED(x) (void)(x) 00070 00071 #elif defined(ESP8266_RTOS) 00072 #define LogInfo(FORMAT, ...) do { \ 00073 static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = FORMAT; \ 00074 printf(flash_str, ##__VA_ARGS__); \ 00075 printf("\n");\ 00076 } while((void)0,0) 00077 00078 #define LogError LogInfo 00079 #define LOG(log_category, log_options, FORMAT, ...) { \ 00080 static const char flash_str[] ICACHE_RODATA_ATTR STORE_ATTR = (FORMAT); \ 00081 printf(flash_str, ##__VA_ARGS__); \ 00082 printf("\r\n"); \ 00083 } 00084 00085 #else /* NOT ESP8266_RTOS */ 00086 00087 #if defined _MSC_VER 00088 #define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, __VA_ARGS__); } 00089 #else 00090 #define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, ##__VA_ARGS__); } 00091 #endif 00092 00093 #if defined _MSC_VER 00094 #define LogInfo(FORMAT, ...) do{LOG(AZ_LOG_INFO, LOG_LINE, FORMAT, __VA_ARGS__); }while((void)0,0) 00095 #else 00096 #define LogInfo(FORMAT, ...) do{LOG(AZ_LOG_INFO, LOG_LINE, FORMAT, ##__VA_ARGS__); }while((void)0,0) 00097 #endif 00098 00099 #ifdef WIN32 00100 extern void xlogging_LogErrorWinHTTPWithGetLastErrorAsStringFormatter(int errorMessageID); 00101 #endif 00102 00103 #if defined _MSC_VER 00104 00105 #if !defined(WINCE) 00106 extern void xlogging_set_log_function_GetLastError(LOGGER_LOG_GETLASTERROR log_function); 00107 extern LOGGER_LOG_GETLASTERROR xlogging_get_log_function_GetLastError(void); 00108 #define LogLastError(FORMAT, ...) do{ LOGGER_LOG_GETLASTERROR l = xlogging_get_log_function_GetLastError(); if(l!=NULL) l(__FILE__, FUNC_NAME, __LINE__, FORMAT, __VA_ARGS__); }while((void)0,0) 00109 #endif 00110 00111 #define LogError(FORMAT, ...) do{ LOG(AZ_LOG_ERROR, LOG_LINE, FORMAT, __VA_ARGS__); }while((void)0,0) 00112 #define LogErrorWinHTTPWithGetLastErrorAsString(FORMAT, ...) do { \ 00113 int errorMessageID = GetLastError(); \ 00114 LogError(FORMAT, __VA_ARGS__); \ 00115 xlogging_LogErrorWinHTTPWithGetLastErrorAsStringFormatter(errorMessageID); \ 00116 } while((void)0,0) 00117 #else // _MSC_VER 00118 #define LogError(FORMAT, ...) do{ LOG(AZ_LOG_ERROR, LOG_LINE, FORMAT, ##__VA_ARGS__); }while((void)0,0) 00119 00120 #ifdef WIN32 00121 // Included when compiling on Windows but not with MSVC, e.g. with MinGW. 00122 #define LogErrorWinHTTPWithGetLastErrorAsString(FORMAT, ...) do { \ 00123 int errorMessageID = GetLastError(); \ 00124 LogError(FORMAT, ##__VA_ARGS__); \ 00125 xlogging_LogErrorWinHTTPWithGetLastErrorAsStringFormatter(errorMessageID); \ 00126 } while((void)0,0) 00127 #endif // WIN32 00128 00129 #endif // _MSC_VER 00130 00131 extern void LogBinary(const char* comment, const void* data, size_t size); 00132 00133 extern void xlogging_set_log_function(LOGGER_LOG log_function); 00134 extern LOGGER_LOG xlogging_get_log_function(void); 00135 00136 #endif /* NOT ESP8266_RTOS */ 00137 00138 #ifdef __cplusplus 00139 } // extern "C" 00140 #endif /* __cplusplus */ 00141 00142 #endif /* XLOGGING_H */
Generated on Wed Jul 13 2022 23:38:02 by
1.7.2