Official reference client implementation for Cumulocity SmartREST on u-blox C027.

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers logging.cpp Source File

logging.cpp

00001 #include <cstdio>
00002 #include <cstdarg>
00003 #include "logging.h"
00004 using namespace std;
00005 
00006 
00007 aLogLevel _level = A_INFO;      // Default log level is INFO.
00008 
00009 int _log(aLogLevel lvl, const char *fmt, va_list& vlist)
00010 {
00011         if (_level <= lvl) {
00012                 int n = 0;
00013                 switch (lvl)
00014                 {
00015                 case A_DEBUG:    n += printf("[DEBUG] ");    break;
00016                 case A_INFO:     n += printf("[INFO] ");     break;
00017                 case A_WARNING:  n += printf("[WARN] ");     break;
00018                 case A_ERROR:    n += printf("[ERROR] ");    break;
00019                 case A_CRITICAL: n += printf("[CRITICAL] "); break;
00020                 default:         n += printf("[UNKNOWN] ");  break;
00021                 }
00022                 return n+vprintf(fmt, vlist);
00023         } else {
00024                 return 0;
00025         }
00026 }
00027 
00028 int aDebug(const char *fmt, ...)
00029 {
00030         va_list vlist;
00031         va_start(vlist, fmt);
00032         int n = _log(A_DEBUG, fmt, vlist);
00033         va_end(vlist);
00034         return n;
00035 }
00036 
00037 int aCritical(const char *fmt, ...)
00038 {
00039         va_list vlist;
00040         va_start(vlist, fmt);
00041         int n = _log(A_CRITICAL, fmt, vlist);
00042         va_end(vlist);
00043         return n;
00044 }
00045 
00046 int aError(const char *fmt, ...)
00047 {
00048         va_list vlist;
00049         va_start(vlist, fmt);
00050         int n = _log(A_ERROR, fmt, vlist);
00051         va_end(vlist);
00052         return n;
00053 }
00054 
00055 int aInfo(const char *fmt, ...)
00056 {
00057         va_list vlist;
00058         va_start(vlist, fmt);
00059         int n = _log(A_INFO, fmt, vlist);
00060         va_end(vlist);
00061         return n;
00062 }
00063 
00064 int aWarning(const char *fmt, ...)
00065 {
00066         va_list vlist;
00067         va_start(vlist, fmt);
00068         int n = _log(A_WARNING, fmt, vlist);
00069         va_end(vlist);
00070         return n;
00071 }
00072 
00073 aLogLevel getLevel()
00074 {
00075         return _level;
00076 }
00077 
00078 void setLevel(aLogLevel lvl)
00079 {
00080         _level = lvl;
00081 }
00082 
00083 void higherOneLevel()
00084 {
00085     switch (_level)
00086     {
00087     case A_DEBUG:    _level = A_INFO;     break;
00088     case A_INFO:     _level = A_WARNING;  break;
00089     case A_WARNING:  _level = A_ERROR;    break;
00090     case A_ERROR:    _level = A_CRITICAL; break;
00091     case A_CRITICAL: _level = A_NONE;     break;
00092     }
00093 }
00094 
00095 void lowerOneLevel()
00096 {
00097     switch (_level)
00098     {
00099     case A_INFO:     _level = A_DEBUG;    break;
00100     case A_WARNING:  _level = A_INFO;     break;
00101     case A_ERROR:    _level = A_WARNING;  break;
00102     case A_CRITICAL: _level = A_ERROR;    break;
00103     case A_NONE:     _level = A_CRITICAL; break;
00104     }
00105 }