Paul Harris / Logger
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cLogger.h Source File

cLogger.h

00001 //*********************************************************************************************************************
00002 //   LOGGER LIBRARY - HEADER FILE
00003 //   PAUL HARRIS, OCTOBER 2016
00004 // *********************************************************************************************************************
00005 
00006 #ifndef LOGGER_H
00007 #define LOGGER_H
00008 
00009 #include "mbed.h"
00010 #include <vector>
00011 #include <stdio.h> 
00012 #include <stdarg.h>
00013 
00014 #include "logger_defs.h"
00015 #include "MODSERIAL.h"
00016 
00017 
00018 class cLogger{
00019     public:
00020         //***********Begin constructor************
00021         cLogger(MODSERIAL* std_out);
00022         //***********End constructor************
00023         
00024         //***********Begin Public member functions************
00025         
00026         //Registers a log area with the logger with specified default log level and prefix
00027         void registerLogArea(eLogArea area, eLogLevel defaultLevel, const char* log_prefix);
00028         //Log the specified formatted log text given the text's specified area and level (printf like formatting variable arguments)
00029         void log(eLogArea area, eLogLevel text_level, char* log_text, ...);
00030         //Log plain formatted text, bypassing any logger level control and without an area prefix (warning: will always be logged!)
00031         void plainText(char* log_text, ...);
00032         //Print a new line
00033         void newLine(void);
00034         //Set the specified log area level
00035         void setLogLevel(eLogArea area, eLogLevel level);
00036         //Set all log areas to the specified log level
00037         void setAllAreaLevels(eLogLevel level);
00038         //Set the specified log area text prefix
00039         void setLogPrefix(eLogArea area, const char* log_prefix);
00040 
00041         //***********End Public member functions************
00042         
00043     private:
00044 
00045         //***********Begin Private member functions************
00046         
00047         //Returns the index in the log_list of the given log area
00048         int getLogListIndex(eLogArea area);
00049         
00050         //Print formatted log text with its associated log level prefix
00051         void printf(eLogArea area, char* log_text, va_list args);
00052         
00053         //***********End Private member functions************
00054         
00055         
00056         //***********Begin Private member variables************
00057         
00058         //Pointer to the MODSERIAL object to use for log output
00059         MODSERIAL* pStdOut;
00060         
00061         //Mutex for making MODSERIAL printf thread safe
00062         Mutex stdio_mutex;
00063         
00064         //Structure to hold log areas and their associated levels/prefixes
00065         struct log_struct
00066         {
00067             eLogArea area;
00068             eLogLevel level;
00069             const char* prefix;
00070         };
00071     
00072         //Type def of log_struct structure
00073         typedef struct log_struct log_t;
00074         
00075         //Vector containers to hold vector of log area structures
00076         std::vector<log_t> log_list;
00077         
00078         //***********End Private member variables************
00079 
00080 };
00081 #endif