Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Committer:
AzureIoTClient
Date:
Fri Nov 03 13:20:36 2017 -0700
Revision:
35:98add15351f3
Parent:
27:8656a313842b
Child:
41:dc93369d5ed4
1.1.27

Who changed what in which revision?

UserRevisionLine numberNew 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
AzureIoTClient 27:8656a313842b 13 void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, int line, unsigned int options, const char* format, ...)
AzureIoTClient 7:1af47e3a19b6 14 {
AzureIoTClient 7:1af47e3a19b6 15 va_list args;
AzureIoTClient 7:1af47e3a19b6 16 va_start(args, format);
AzureIoTClient 7:1af47e3a19b6 17
AzureIoTClient 7:1af47e3a19b6 18 time_t t = time(NULL);
AzureIoTClient 7:1af47e3a19b6 19
AzureIoTClient 7:1af47e3a19b6 20 switch (log_category)
AzureIoTClient 7:1af47e3a19b6 21 {
AzureIoTClient 18:6d8a413a4d9a 22 case AZ_LOG_INFO:
AzureIoTClient 7:1af47e3a19b6 23 (void)printf("Info: ");
AzureIoTClient 7:1af47e3a19b6 24 break;
AzureIoTClient 18:6d8a413a4d9a 25 case AZ_LOG_ERROR:
AzureIoTClient 8:3db46d1e5471 26 (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), file, func, line);
AzureIoTClient 7:1af47e3a19b6 27 break;
AzureIoTClient 7:1af47e3a19b6 28 default:
AzureIoTClient 7:1af47e3a19b6 29 break;
AzureIoTClient 7:1af47e3a19b6 30 }
AzureIoTClient 7:1af47e3a19b6 31
AzureIoTClient 7:1af47e3a19b6 32 (void)vprintf(format, args);
AzureIoTClient 7:1af47e3a19b6 33 va_end(args);
AzureIoTClient 7:1af47e3a19b6 34
AzureIoTClient 7:1af47e3a19b6 35 (void)log_category;
AzureIoTClient 7:1af47e3a19b6 36 if (options & LOG_LINE)
AzureIoTClient 7:1af47e3a19b6 37 {
AzureIoTClient 7:1af47e3a19b6 38 (void)printf("\r\n");
AzureIoTClient 7:1af47e3a19b6 39 }
AzureIoTClient 7:1af47e3a19b6 40 }
AzureIoTClient 7:1af47e3a19b6 41 #endif
AzureIoTClient 7:1af47e3a19b6 42
AzureIoTClient 7:1af47e3a19b6 43 LOGGER_LOG global_log_function = consolelogger_log;
AzureIoTClient 7:1af47e3a19b6 44
Azure.IoT Build 6:c55b013dfc2a 45 void xlogging_set_log_function(LOGGER_LOG log_function)
Azure.IoT Build 6:c55b013dfc2a 46 {
Azure.IoT Build 6:c55b013dfc2a 47 global_log_function = log_function;
Azure.IoT Build 6:c55b013dfc2a 48 }
Azure.IoT Build 6:c55b013dfc2a 49
Azure.IoT Build 6:c55b013dfc2a 50 LOGGER_LOG xlogging_get_log_function(void)
Azure.IoT Build 6:c55b013dfc2a 51 {
Azure.IoT Build 6:c55b013dfc2a 52 return global_log_function;
Azure.IoT Build 6:c55b013dfc2a 53 }
AzureIoTClient 7:1af47e3a19b6 54
AzureIoTClient 27:8656a313842b 55 #if (defined(_MSC_VER)) && (!(defined WINCE))
AzureIoTClient 27:8656a313842b 56
AzureIoTClient 27:8656a313842b 57 LOGGER_LOG_GETLASTERROR global_log_function_GetLastError = consolelogger_log_with_GetLastError;
AzureIoTClient 27:8656a313842b 58
AzureIoTClient 27:8656a313842b 59 void xlogging_set_log_function_GetLastError(LOGGER_LOG_GETLASTERROR log_function_GetLastError)
AzureIoTClient 27:8656a313842b 60 {
AzureIoTClient 27:8656a313842b 61 global_log_function_GetLastError = log_function_GetLastError;
AzureIoTClient 27:8656a313842b 62 }
AzureIoTClient 27:8656a313842b 63
AzureIoTClient 27:8656a313842b 64 LOGGER_LOG_GETLASTERROR xlogging_get_log_function_GetLastError(void)
AzureIoTClient 27:8656a313842b 65 {
AzureIoTClient 27:8656a313842b 66 return global_log_function_GetLastError;
AzureIoTClient 27:8656a313842b 67 }
AzureIoTClient 27:8656a313842b 68 #endif
AzureIoTClient 27:8656a313842b 69
AzureIoTClient 7:1af47e3a19b6 70 #endif