Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 /**
vpcola 0:f1d3878b8dd9 2 * Copyright (c) 2015 Digi International Inc.,
vpcola 0:f1d3878b8dd9 3 * All rights not expressly granted are reserved.
vpcola 0:f1d3878b8dd9 4 *
vpcola 0:f1d3878b8dd9 5 * This Source Code Form is subject to the terms of the Mozilla Public
vpcola 0:f1d3878b8dd9 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
vpcola 0:f1d3878b8dd9 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
vpcola 0:f1d3878b8dd9 8 *
vpcola 0:f1d3878b8dd9 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
vpcola 0:f1d3878b8dd9 10 * =======================================================================
vpcola 0:f1d3878b8dd9 11 */
vpcola 0:f1d3878b8dd9 12
vpcola 0:f1d3878b8dd9 13 #include "DigiLogger.h"
vpcola 0:f1d3878b8dd9 14
vpcola 0:f1d3878b8dd9 15 #include <stdarg.h>
vpcola 0:f1d3878b8dd9 16
vpcola 0:f1d3878b8dd9 17 using namespace DigiLog;
vpcola 0:f1d3878b8dd9 18
vpcola 0:f1d3878b8dd9 19 LogLevel DigiLogger::_log_level;
vpcola 0:f1d3878b8dd9 20
vpcola 0:f1d3878b8dd9 21 DigiLogger* DigiLogger::current_logger;
vpcola 0:f1d3878b8dd9 22
vpcola 0:f1d3878b8dd9 23 /* Base Class constructor */
vpcola 0:f1d3878b8dd9 24 DigiLogger::DigiLogger()
vpcola 0:f1d3878b8dd9 25 {
vpcola 0:f1d3878b8dd9 26 _log_level = LogLevelNone;
vpcola 0:f1d3878b8dd9 27
vpcola 0:f1d3878b8dd9 28 current_logger = NULL;
vpcola 0:f1d3878b8dd9 29 }
vpcola 0:f1d3878b8dd9 30
vpcola 0:f1d3878b8dd9 31 /* Class destructor */
vpcola 0:f1d3878b8dd9 32 DigiLogger::~DigiLogger()
vpcola 0:f1d3878b8dd9 33 {
vpcola 0:f1d3878b8dd9 34 current_logger = NULL;
vpcola 0:f1d3878b8dd9 35 }
vpcola 0:f1d3878b8dd9 36
vpcola 0:f1d3878b8dd9 37 void DigiLogger::set_level(LogLevel log_level)
vpcola 0:f1d3878b8dd9 38 {
vpcola 0:f1d3878b8dd9 39 _log_level = log_level;
vpcola 0:f1d3878b8dd9 40 }
vpcola 0:f1d3878b8dd9 41
vpcola 0:f1d3878b8dd9 42 LogLevel DigiLogger::get_level()
vpcola 0:f1d3878b8dd9 43 {
vpcola 0:f1d3878b8dd9 44 return _log_level;
vpcola 0:f1d3878b8dd9 45 }
vpcola 0:f1d3878b8dd9 46
vpcola 0:f1d3878b8dd9 47 void DigiLogger::log_format(LogLevel log_level, const char *format, ...)
vpcola 0:f1d3878b8dd9 48 {
vpcola 0:f1d3878b8dd9 49 static char buffer[DEBUG_BUFFER_LEN];
vpcola 0:f1d3878b8dd9 50 va_list argp;
vpcola 0:f1d3878b8dd9 51
vpcola 0:f1d3878b8dd9 52 if (current_logger == NULL) {
vpcola 0:f1d3878b8dd9 53 return;
vpcola 0:f1d3878b8dd9 54 }
vpcola 0:f1d3878b8dd9 55
vpcola 0:f1d3878b8dd9 56 if (_log_level < log_level) {
vpcola 0:f1d3878b8dd9 57 return;
vpcola 0:f1d3878b8dd9 58 }
vpcola 0:f1d3878b8dd9 59
vpcola 0:f1d3878b8dd9 60 va_start(argp, format);
vpcola 0:f1d3878b8dd9 61 vsnprintf(buffer, DEBUG_BUFFER_LEN, format, argp);
vpcola 0:f1d3878b8dd9 62 va_end(argp);
vpcola 0:f1d3878b8dd9 63
vpcola 0:f1d3878b8dd9 64 current_logger->log_buffer(buffer);
vpcola 0:f1d3878b8dd9 65 }
vpcola 0:f1d3878b8dd9 66
vpcola 0:f1d3878b8dd9 67 void DigiLogger::log_buffer(char const * const buffer)
vpcola 0:f1d3878b8dd9 68 {
vpcola 0:f1d3878b8dd9 69 (void)(buffer);
vpcola 0:f1d3878b8dd9 70 }