Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MyLog.cpp Source File

MyLog.cpp

00001 /*
00002  * MyLog.cpp
00003  *
00004  *  Heavily borrowed from MTSLog
00005  *
00006  *  Created on: Mar 14, 2017
00007  *      Author: mbriggs
00008  */
00009 
00010 #include "MyLog.h"
00011 
00012 #include "mbed.h"
00013 #include <stdarg.h>
00014 
00015 using namespace mts;
00016 
00017 int MyLog::currentLevel = MyLog::WARNING_LEVEL;
00018 
00019 const char* MyLog::NONE_LABEL = "NONE";
00020 const char* MyLog::FATAL_LABEL = "FATAL";
00021 const char* MyLog::ERROR_LABEL = "ERROR";
00022 const char* MyLog::WARNING_LABEL = "WARNING";
00023 const char* MyLog::INFO_LABEL = "INFO";
00024 const char* MyLog::DEBUG_LABEL = "DEBUG";
00025 const char* MyLog::TRACE_LABEL = "TRACE";
00026 
00027 void MyLog::printMessage(int level, const char* format, ...) {
00028     if (printable(level)) {
00029         va_list argptr;
00030         va_start(argptr, format);
00031         vprintf(format, argptr);
00032         va_end(argptr);
00033     }
00034 }
00035 
00036 bool MyLog::printable(int level) {
00037     return level <= currentLevel;
00038 }
00039 
00040 void MyLog::setLogLevel(int level) {
00041     if (level < NONE_LEVEL)
00042         currentLevel = NONE_LEVEL;
00043     else if (level > TRACE_LEVEL)
00044         currentLevel = TRACE_LEVEL;
00045     else
00046     currentLevel = level;
00047 }
00048 
00049 int MyLog::getLogLevel() {
00050     return currentLevel;
00051 }
00052 
00053 const char* MyLog::getLogLevelString() {
00054     switch (currentLevel) {
00055         case NONE_LEVEL:
00056             return NONE_LABEL;
00057         case FATAL_LEVEL:
00058             return FATAL_LABEL;
00059         case ERROR_LEVEL:
00060             return ERROR_LABEL;
00061         case WARNING_LEVEL:
00062             return WARNING_LABEL;
00063         case INFO_LEVEL:
00064             return INFO_LABEL;
00065         case DEBUG_LEVEL:
00066             return DEBUG_LABEL;
00067         case TRACE_LEVEL:
00068             return TRACE_LABEL;
00069         default:
00070             return "unknown";
00071     }
00072 }