Azure IoT common library
Fork of azure_c_shared_utility by
xlogging.c@7:1af47e3a19b6, 2016-07-29 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Jul 29 16:01:07 2016 -0700
- Revision:
- 7:1af47e3a19b6
- Parent:
- 6:c55b013dfc2a
- Child:
- 8:3db46d1e5471
1.0.10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Azure.IoT Build | 6:c55b013dfc2a | 1 | // Copyright (c) Microsoft. All rights reserved. |
Azure.IoT Build | 6:c55b013dfc2a | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
Azure.IoT Build | 6:c55b013dfc2a | 3 | |
Azure.IoT Build | 6:c55b013dfc2a | 4 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT Build | 6:c55b013dfc2a | 5 | #include "azure_c_shared_utility/consolelogger.h" |
Azure.IoT Build | 6:c55b013dfc2a | 6 | |
AzureIoTClient | 7:1af47e3a19b6 | 7 | #ifndef NO_LOGGING |
AzureIoTClient | 7:1af47e3a19b6 | 8 | |
AzureIoTClient | 7:1af47e3a19b6 | 9 | |
AzureIoTClient | 7:1af47e3a19b6 | 10 | #ifdef WINCE |
AzureIoTClient | 7:1af47e3a19b6 | 11 | #include <stdarg.h> |
AzureIoTClient | 7:1af47e3a19b6 | 12 | #if defined _MSC_VER |
AzureIoTClient | 7:1af47e3a19b6 | 13 | #define FUNC_NAME __FUNCDNAME__ |
AzureIoTClient | 7:1af47e3a19b6 | 14 | #else |
AzureIoTClient | 7:1af47e3a19b6 | 15 | #define FUNC_NAME __func__ |
AzureIoTClient | 7:1af47e3a19b6 | 16 | #endif |
AzureIoTClient | 7:1af47e3a19b6 | 17 | |
AzureIoTClient | 7:1af47e3a19b6 | 18 | void consolelogger_log(LOG_CATEGORY log_category, unsigned int options, const char* format, ...) |
AzureIoTClient | 7:1af47e3a19b6 | 19 | { |
AzureIoTClient | 7:1af47e3a19b6 | 20 | va_list args; |
AzureIoTClient | 7:1af47e3a19b6 | 21 | va_start(args, format); |
AzureIoTClient | 7:1af47e3a19b6 | 22 | |
AzureIoTClient | 7:1af47e3a19b6 | 23 | time_t t = time(NULL); |
AzureIoTClient | 7:1af47e3a19b6 | 24 | |
AzureIoTClient | 7:1af47e3a19b6 | 25 | switch (log_category) |
AzureIoTClient | 7:1af47e3a19b6 | 26 | { |
AzureIoTClient | 7:1af47e3a19b6 | 27 | case LOG_INFO: |
AzureIoTClient | 7:1af47e3a19b6 | 28 | (void)printf("Info: "); |
AzureIoTClient | 7:1af47e3a19b6 | 29 | break; |
AzureIoTClient | 7:1af47e3a19b6 | 30 | case LOG_ERROR: |
AzureIoTClient | 7:1af47e3a19b6 | 31 | (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), __FILE__, FUNC_NAME, __LINE__); |
AzureIoTClient | 7:1af47e3a19b6 | 32 | break; |
AzureIoTClient | 7:1af47e3a19b6 | 33 | default: |
AzureIoTClient | 7:1af47e3a19b6 | 34 | break; |
AzureIoTClient | 7:1af47e3a19b6 | 35 | } |
AzureIoTClient | 7:1af47e3a19b6 | 36 | |
AzureIoTClient | 7:1af47e3a19b6 | 37 | (void)vprintf(format, args); |
AzureIoTClient | 7:1af47e3a19b6 | 38 | va_end(args); |
AzureIoTClient | 7:1af47e3a19b6 | 39 | |
AzureIoTClient | 7:1af47e3a19b6 | 40 | (void)log_category; |
AzureIoTClient | 7:1af47e3a19b6 | 41 | if (options & LOG_LINE) |
AzureIoTClient | 7:1af47e3a19b6 | 42 | { |
AzureIoTClient | 7:1af47e3a19b6 | 43 | (void)printf("\r\n"); |
AzureIoTClient | 7:1af47e3a19b6 | 44 | } |
AzureIoTClient | 7:1af47e3a19b6 | 45 | } |
AzureIoTClient | 7:1af47e3a19b6 | 46 | #endif |
AzureIoTClient | 7:1af47e3a19b6 | 47 | |
AzureIoTClient | 7:1af47e3a19b6 | 48 | LOGGER_LOG global_log_function = consolelogger_log; |
AzureIoTClient | 7:1af47e3a19b6 | 49 | |
Azure.IoT Build | 6:c55b013dfc2a | 50 | |
Azure.IoT Build | 6:c55b013dfc2a | 51 | void xlogging_set_log_function(LOGGER_LOG log_function) |
Azure.IoT Build | 6:c55b013dfc2a | 52 | { |
Azure.IoT Build | 6:c55b013dfc2a | 53 | global_log_function = log_function; |
Azure.IoT Build | 6:c55b013dfc2a | 54 | } |
Azure.IoT Build | 6:c55b013dfc2a | 55 | |
Azure.IoT Build | 6:c55b013dfc2a | 56 | LOGGER_LOG xlogging_get_log_function(void) |
Azure.IoT Build | 6:c55b013dfc2a | 57 | { |
Azure.IoT Build | 6:c55b013dfc2a | 58 | return global_log_function; |
Azure.IoT Build | 6:c55b013dfc2a | 59 | } |
AzureIoTClient | 7:1af47e3a19b6 | 60 | |
AzureIoTClient | 7:1af47e3a19b6 | 61 | #endif |