Portado para MBED OS 6

Dependents:   Navitec-Firmware

Committer:
renanbmx123
Date:
Sun Apr 04 14:38:12 2021 +0000
Revision:
6:3fdb7f0f121a
Parent:
5:58c5158b5120
Refatorado;

Who changed what in which revision?

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