-
Notifications
You must be signed in to change notification settings - Fork 127
/
Logging.h
146 lines (125 loc) · 3.8 KB
/
Logging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef LOGGING_H
#define LOGGING_H
#include <inttypes.h>
#include <stdarg.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
//#include "pins_arduino.h"
extern "C" {
#include <avr/io.h>
}
#define LOG_LEVEL_NOOUTPUT 0
#define LOG_LEVEL_ERRORS 1
#define LOG_LEVEL_INFOS 2
#define LOG_LEVEL_DEBUG 3
#define LOG_LEVEL_VERBOSE 4
// default loglevel if nothing is set from user
#define LOGLEVEL LOG_LEVEL_DEBUG
#define CR "\r\n"
#define LOGGING_VERSION 1
/*!
* Logging is a helper class to output informations over
* RS232. If you know log4j or log4net, this logging class
* is more or less similar ;-) <br>
* Different loglevels can be used to extend or reduce output
* All methods are able to handle any number of output parameters.
* All methods print out a formated string (like printf).<br>
* To reduce output and program size, reduce loglevel.
* <br>
* Output format string can contain below wildcards. Every wildcard
* must be start with percent sign (\%)
*
* <b>Depending on loglevel, source code is excluded from compile !</b><br>
* <br>
* <b>Wildcards</b><br>
* <ul>
* <li><b>\%s</b> replace with an string (char*)</li>
* <li><b>\%c</b> replace with an character</li>
* <li><b>\%d</b> replace with an integer value</li>
* <li><b>\%l</b> replace with an long value</li>
* <li><b>\%x</b> replace and convert integer value into hex</li>
* <li><b>\%X</b> like %x but combine with <b>0x</b>123AB</li>
* <li><b>\%b</b> replace and convert integer value into binary</li>
* <li><b>\%B</b> like %x but combine with <b>0b</b>10100011</li>
* <li><b>\%t</b> replace and convert boolean value into <b>"t"</b> or <b>"f"</b></li>
* <li><b>\%T</b> like %t but convert into <b>"true"</b> or <b>"false"</b></li>
* </ul><br>
* <b>Loglevels</b><br>
* <table border="0">
* <tr><td>0</td><td>LOG_LEVEL_NOOUTPUT</td><td>no output </td></tr>
* <tr><td>1</td><td>LOG_LEVEL_ERRORS</td><td>only errors </td></tr>
* <tr><td>2</td><td>LOG_LEVEL_INFOS</td><td>errors and info </td></tr>
* <tr><td>3</td><td>LOG_LEVEL_DEBUG</td><td>errors, info and debug </td></tr>
* <tr><td>4</td><td>LOG_LEVEL_VERBOSE</td><td>all </td></tr>
* </table>
* <br>
* <h1>History</h1><br>
* <table border="0">
* <tr><td>01 FEB 2012</td><td>initial release</td></tr>
* <tr><td>06 MAR 2012</td><td>implement a preinstanciate object (like in Wire, ...)</td></tr>
* <tr><td></td><td>methode init get now loglevel and baud parameter</td></tr>
*/
class Logging {
private:
int _level;
long _baud;
public:
/*!
* default Constructor
*/
Logging(){} ;
/**
* Initializing, must be called as first.
* \param void
* \return void
*
*/
void Init(int level, long baud);
/**
* Output an error message. Output message contains
* ERROR: followed by original msg
* Error messages are printed out, at every loglevel
* except 0 ;-)
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
void Error(char* msg, ...);
/**
* Output an info message. Output message contains
* Info messages are printed out at l
* loglevels >= LOG_LEVEL_INFOS
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
void Info(char* msg, ...);
/**
* Output an debug message. Output message contains
* Debug messages are printed out at l
* loglevels >= LOG_LEVEL_DEBUG
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
void Debug(char* msg, ...);
/**
* Output an verbose message. Output message contains
* Debug messages are printed out at l
* loglevels >= LOG_LEVEL_VERBOSE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
void Verbose(char* msg, ...);
private:
void print(const char *format, va_list args);
};
extern Logging Log;
#endif