Provides the means to log debug text to various log areas and at various severity levels and send it to a MODSERIAL serial port object for output.
cLogger.h@2:f1b41864f865, 2017-06-30 (annotated)
- Committer:
- paul_harris77
- Date:
- Fri Jun 30 16:36:48 2017 +0000
- Revision:
- 2:f1b41864f865
- Parent:
- 0:23f7bb983ae0
Updated for compatibility with LidarLitev3 program. Removed extern global declaration of logger object. cSystemControl object now instantiates all required objects and injects cLogger object dependency in to constructor of each object.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| paul_harris77 | 0:23f7bb983ae0 | 1 | //********************************************************************************************************************* |
| paul_harris77 | 0:23f7bb983ae0 | 2 | // LOGGER LIBRARY - HEADER FILE |
| paul_harris77 | 0:23f7bb983ae0 | 3 | // PAUL HARRIS, OCTOBER 2016 |
| paul_harris77 | 0:23f7bb983ae0 | 4 | // ********************************************************************************************************************* |
| paul_harris77 | 0:23f7bb983ae0 | 5 | |
| paul_harris77 | 0:23f7bb983ae0 | 6 | #ifndef LOGGER_H |
| paul_harris77 | 0:23f7bb983ae0 | 7 | #define LOGGER_H |
| paul_harris77 | 0:23f7bb983ae0 | 8 | |
| paul_harris77 | 0:23f7bb983ae0 | 9 | #include "mbed.h" |
| paul_harris77 | 0:23f7bb983ae0 | 10 | #include <vector> |
| paul_harris77 | 0:23f7bb983ae0 | 11 | #include <stdio.h> |
| paul_harris77 | 0:23f7bb983ae0 | 12 | #include <stdarg.h> |
| paul_harris77 | 0:23f7bb983ae0 | 13 | |
| paul_harris77 | 0:23f7bb983ae0 | 14 | #include "logger_defs.h" |
| paul_harris77 | 0:23f7bb983ae0 | 15 | #include "MODSERIAL.h" |
| paul_harris77 | 0:23f7bb983ae0 | 16 | |
| paul_harris77 | 0:23f7bb983ae0 | 17 | |
| paul_harris77 | 0:23f7bb983ae0 | 18 | class cLogger{ |
| paul_harris77 | 0:23f7bb983ae0 | 19 | public: |
| paul_harris77 | 0:23f7bb983ae0 | 20 | //***********Begin constructor************ |
| paul_harris77 | 0:23f7bb983ae0 | 21 | cLogger(MODSERIAL* std_out); |
| paul_harris77 | 0:23f7bb983ae0 | 22 | //***********End constructor************ |
| paul_harris77 | 0:23f7bb983ae0 | 23 | |
| paul_harris77 | 0:23f7bb983ae0 | 24 | //***********Begin Public member functions************ |
| paul_harris77 | 0:23f7bb983ae0 | 25 | |
| paul_harris77 | 0:23f7bb983ae0 | 26 | //Registers a log area with the logger with specified default log level and prefix |
| paul_harris77 | 0:23f7bb983ae0 | 27 | void registerLogArea(eLogArea area, eLogLevel defaultLevel, const char* log_prefix); |
| paul_harris77 | 0:23f7bb983ae0 | 28 | //Log the specified formatted log text given the text's specified area and level (printf like formatting variable arguments) |
| paul_harris77 | 0:23f7bb983ae0 | 29 | void log(eLogArea area, eLogLevel text_level, char* log_text, ...); |
| paul_harris77 | 0:23f7bb983ae0 | 30 | //Log plain formatted text, bypassing any logger level control and without an area prefix (warning: will always be logged!) |
| paul_harris77 | 0:23f7bb983ae0 | 31 | void plainText(char* log_text, ...); |
| paul_harris77 | 0:23f7bb983ae0 | 32 | //Print a new line |
| paul_harris77 | 0:23f7bb983ae0 | 33 | void newLine(void); |
| paul_harris77 | 0:23f7bb983ae0 | 34 | //Set the specified log area level |
| paul_harris77 | 0:23f7bb983ae0 | 35 | void setLogLevel(eLogArea area, eLogLevel level); |
| paul_harris77 | 0:23f7bb983ae0 | 36 | //Set all log areas to the specified log level |
| paul_harris77 | 0:23f7bb983ae0 | 37 | void setAllAreaLevels(eLogLevel level); |
| paul_harris77 | 0:23f7bb983ae0 | 38 | //Set the specified log area text prefix |
| paul_harris77 | 0:23f7bb983ae0 | 39 | void setLogPrefix(eLogArea area, const char* log_prefix); |
| paul_harris77 | 0:23f7bb983ae0 | 40 | |
| paul_harris77 | 0:23f7bb983ae0 | 41 | //***********End Public member functions************ |
| paul_harris77 | 0:23f7bb983ae0 | 42 | |
| paul_harris77 | 0:23f7bb983ae0 | 43 | private: |
| paul_harris77 | 0:23f7bb983ae0 | 44 | |
| paul_harris77 | 0:23f7bb983ae0 | 45 | //***********Begin Private member functions************ |
| paul_harris77 | 0:23f7bb983ae0 | 46 | |
| paul_harris77 | 0:23f7bb983ae0 | 47 | //Returns the index in the log_list of the given log area |
| paul_harris77 | 0:23f7bb983ae0 | 48 | int getLogListIndex(eLogArea area); |
| paul_harris77 | 0:23f7bb983ae0 | 49 | |
| paul_harris77 | 0:23f7bb983ae0 | 50 | //Print formatted log text with its associated log level prefix |
| paul_harris77 | 0:23f7bb983ae0 | 51 | void printf(eLogArea area, char* log_text, va_list args); |
| paul_harris77 | 0:23f7bb983ae0 | 52 | |
| paul_harris77 | 0:23f7bb983ae0 | 53 | //***********End Private member functions************ |
| paul_harris77 | 0:23f7bb983ae0 | 54 | |
| paul_harris77 | 0:23f7bb983ae0 | 55 | |
| paul_harris77 | 0:23f7bb983ae0 | 56 | //***********Begin Private member variables************ |
| paul_harris77 | 0:23f7bb983ae0 | 57 | |
| paul_harris77 | 0:23f7bb983ae0 | 58 | //Pointer to the MODSERIAL object to use for log output |
| paul_harris77 | 0:23f7bb983ae0 | 59 | MODSERIAL* pStdOut; |
| paul_harris77 | 0:23f7bb983ae0 | 60 | |
| paul_harris77 | 0:23f7bb983ae0 | 61 | //Mutex for making MODSERIAL printf thread safe |
| paul_harris77 | 0:23f7bb983ae0 | 62 | Mutex stdio_mutex; |
| paul_harris77 | 0:23f7bb983ae0 | 63 | |
| paul_harris77 | 0:23f7bb983ae0 | 64 | //Structure to hold log areas and their associated levels/prefixes |
| paul_harris77 | 0:23f7bb983ae0 | 65 | struct log_struct |
| paul_harris77 | 0:23f7bb983ae0 | 66 | { |
| paul_harris77 | 0:23f7bb983ae0 | 67 | eLogArea area; |
| paul_harris77 | 0:23f7bb983ae0 | 68 | eLogLevel level; |
| paul_harris77 | 0:23f7bb983ae0 | 69 | const char* prefix; |
| paul_harris77 | 0:23f7bb983ae0 | 70 | }; |
| paul_harris77 | 0:23f7bb983ae0 | 71 | |
| paul_harris77 | 0:23f7bb983ae0 | 72 | //Type def of log_struct structure |
| paul_harris77 | 0:23f7bb983ae0 | 73 | typedef struct log_struct log_t; |
| paul_harris77 | 0:23f7bb983ae0 | 74 | |
| paul_harris77 | 0:23f7bb983ae0 | 75 | //Vector containers to hold vector of log area structures |
| paul_harris77 | 0:23f7bb983ae0 | 76 | std::vector<log_t> log_list; |
| paul_harris77 | 0:23f7bb983ae0 | 77 | |
| paul_harris77 | 0:23f7bb983ae0 | 78 | //***********End Private member variables************ |
| paul_harris77 | 0:23f7bb983ae0 | 79 | |
| paul_harris77 | 0:23f7bb983ae0 | 80 | }; |
| paul_harris77 | 0:23f7bb983ae0 | 81 | #endif |