Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Mon Aug 08 11:05:57 2016 +0000
Revision:
138:f8ab852e83e7
Parent:
77:f6717e4eccc4
Etisalat and Teleena APN.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xinlei 72:c5709ae7b193 1 #include <cstdio>
xinlei 72:c5709ae7b193 2 #include <cstdarg>
xinlei 72:c5709ae7b193 3 #include "logging.h"
xinlei 72:c5709ae7b193 4 using namespace std;
xinlei 72:c5709ae7b193 5
xinlei 72:c5709ae7b193 6
xinlei 72:c5709ae7b193 7 aLogLevel _level = A_INFO; // Default log level is INFO.
xinlei 72:c5709ae7b193 8
xinlei 72:c5709ae7b193 9 int _log(aLogLevel lvl, const char *fmt, va_list& vlist)
xinlei 72:c5709ae7b193 10 {
xinlei 72:c5709ae7b193 11 if (_level <= lvl) {
xinlei 72:c5709ae7b193 12 int n = 0;
xinlei 72:c5709ae7b193 13 switch (lvl)
xinlei 72:c5709ae7b193 14 {
xinlei 72:c5709ae7b193 15 case A_DEBUG: n += printf("[DEBUG] "); break;
xinlei 77:f6717e4eccc4 16 case A_INFO: n += printf("[INFO] "); break;
xinlei 72:c5709ae7b193 17 case A_WARNING: n += printf("[WARN] "); break;
xinlei 72:c5709ae7b193 18 case A_ERROR: n += printf("[ERROR] "); break;
xinlei 72:c5709ae7b193 19 case A_CRITICAL: n += printf("[CRITICAL] "); break;
xinlei 72:c5709ae7b193 20 default: n += printf("[UNKNOWN] "); break;
xinlei 72:c5709ae7b193 21 }
xinlei 72:c5709ae7b193 22 return n+vprintf(fmt, vlist);
xinlei 72:c5709ae7b193 23 } else {
xinlei 72:c5709ae7b193 24 return 0;
xinlei 72:c5709ae7b193 25 }
xinlei 72:c5709ae7b193 26 }
xinlei 72:c5709ae7b193 27
xinlei 72:c5709ae7b193 28 int aDebug(const char *fmt, ...)
xinlei 72:c5709ae7b193 29 {
xinlei 72:c5709ae7b193 30 va_list vlist;
xinlei 72:c5709ae7b193 31 va_start(vlist, fmt);
xinlei 72:c5709ae7b193 32 int n = _log(A_DEBUG, fmt, vlist);
xinlei 72:c5709ae7b193 33 va_end(vlist);
xinlei 72:c5709ae7b193 34 return n;
xinlei 72:c5709ae7b193 35 }
xinlei 72:c5709ae7b193 36
xinlei 72:c5709ae7b193 37 int aCritical(const char *fmt, ...)
xinlei 72:c5709ae7b193 38 {
xinlei 72:c5709ae7b193 39 va_list vlist;
xinlei 72:c5709ae7b193 40 va_start(vlist, fmt);
xinlei 72:c5709ae7b193 41 int n = _log(A_CRITICAL, fmt, vlist);
xinlei 72:c5709ae7b193 42 va_end(vlist);
xinlei 72:c5709ae7b193 43 return n;
xinlei 72:c5709ae7b193 44 }
xinlei 72:c5709ae7b193 45
xinlei 72:c5709ae7b193 46 int aError(const char *fmt, ...)
xinlei 72:c5709ae7b193 47 {
xinlei 72:c5709ae7b193 48 va_list vlist;
xinlei 72:c5709ae7b193 49 va_start(vlist, fmt);
xinlei 72:c5709ae7b193 50 int n = _log(A_ERROR, fmt, vlist);
xinlei 72:c5709ae7b193 51 va_end(vlist);
xinlei 72:c5709ae7b193 52 return n;
xinlei 72:c5709ae7b193 53 }
xinlei 72:c5709ae7b193 54
xinlei 72:c5709ae7b193 55 int aInfo(const char *fmt, ...)
xinlei 72:c5709ae7b193 56 {
xinlei 72:c5709ae7b193 57 va_list vlist;
xinlei 72:c5709ae7b193 58 va_start(vlist, fmt);
xinlei 72:c5709ae7b193 59 int n = _log(A_INFO, fmt, vlist);
xinlei 72:c5709ae7b193 60 va_end(vlist);
xinlei 72:c5709ae7b193 61 return n;
xinlei 72:c5709ae7b193 62 }
xinlei 72:c5709ae7b193 63
xinlei 72:c5709ae7b193 64 int aWarning(const char *fmt, ...)
xinlei 72:c5709ae7b193 65 {
xinlei 72:c5709ae7b193 66 va_list vlist;
xinlei 72:c5709ae7b193 67 va_start(vlist, fmt);
xinlei 72:c5709ae7b193 68 int n = _log(A_WARNING, fmt, vlist);
xinlei 72:c5709ae7b193 69 va_end(vlist);
xinlei 72:c5709ae7b193 70 return n;
xinlei 72:c5709ae7b193 71 }
xinlei 72:c5709ae7b193 72
xinlei 72:c5709ae7b193 73 aLogLevel getLevel()
xinlei 72:c5709ae7b193 74 {
xinlei 72:c5709ae7b193 75 return _level;
xinlei 72:c5709ae7b193 76 }
xinlei 72:c5709ae7b193 77
xinlei 72:c5709ae7b193 78 void setLevel(aLogLevel lvl)
xinlei 72:c5709ae7b193 79 {
xinlei 72:c5709ae7b193 80 _level = lvl;
xinlei 72:c5709ae7b193 81 }
xinlei 77:f6717e4eccc4 82
xinlei 77:f6717e4eccc4 83 void higherOneLevel()
xinlei 77:f6717e4eccc4 84 {
xinlei 77:f6717e4eccc4 85 switch (_level)
xinlei 77:f6717e4eccc4 86 {
xinlei 77:f6717e4eccc4 87 case A_DEBUG: _level = A_INFO; break;
xinlei 77:f6717e4eccc4 88 case A_INFO: _level = A_WARNING; break;
xinlei 77:f6717e4eccc4 89 case A_WARNING: _level = A_ERROR; break;
xinlei 77:f6717e4eccc4 90 case A_ERROR: _level = A_CRITICAL; break;
xinlei 77:f6717e4eccc4 91 case A_CRITICAL: _level = A_NONE; break;
xinlei 77:f6717e4eccc4 92 }
xinlei 77:f6717e4eccc4 93 }
xinlei 77:f6717e4eccc4 94
xinlei 77:f6717e4eccc4 95 void lowerOneLevel()
xinlei 77:f6717e4eccc4 96 {
xinlei 77:f6717e4eccc4 97 switch (_level)
xinlei 77:f6717e4eccc4 98 {
xinlei 77:f6717e4eccc4 99 case A_INFO: _level = A_DEBUG; break;
xinlei 77:f6717e4eccc4 100 case A_WARNING: _level = A_INFO; break;
xinlei 77:f6717e4eccc4 101 case A_ERROR: _level = A_WARNING; break;
xinlei 77:f6717e4eccc4 102 case A_CRITICAL: _level = A_ERROR; break;
xinlei 77:f6717e4eccc4 103 case A_NONE: _level = A_CRITICAL; break;
xinlei 77:f6717e4eccc4 104 }
xinlei 77:f6717e4eccc4 105 }