1
1
/*
2
- _ ___ ___ _ _ ___ _ _ ___ _ ___ ___
2
+ _ ___ ___ _ _ ___ _ _ ___ _ ___ ___
3
3
/_\ | _ \ \| | | |_ _| \| |/ _ \| | / _ \ / __|
4
4
/ _ \| / |) | |_| || || .` | (_) | |_| (_) | (_ |
5
5
/_/ \_\_|_\___/ \___/|___|_|\_|\___/|____\___/ \___|
6
-
6
+
7
7
Log library for Arduino
8
8
version 1.0.0
9
9
https://github.com/thijse/Arduino-Log
@@ -30,7 +30,7 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
30
30
// #define DISABLE_LOGGING
31
31
32
32
33
- #define LOG_LEVEL_SILENT 0
33
+ #define LOG_LEVEL_SILENT 0
34
34
#define LOG_LEVEL_FATAL 1
35
35
#define LOG_LEVEL_ERROR 2
36
36
#define LOG_LEVEL_WARNING 3
@@ -49,12 +49,12 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
49
49
All methods are able to handle any number of output parameters.
50
50
All methods print out a formated string (like printf).<br>
51
51
To reduce output and program size, reduce loglevel.
52
-
52
+
53
53
Output format string can contain below wildcards. Every wildcard
54
54
must be start with percent sign (\%)
55
-
55
+
56
56
**** Wildcards
57
-
57
+
58
58
* %s replace with an string (char*)
59
59
* %c replace with an character
60
60
* %d replace with an integer value
@@ -68,13 +68,13 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
68
68
69
69
**** Loglevels
70
70
71
- * 0 - LOG_LEVEL_SILENT no output
72
- * 1 - LOG_LEVEL_FATAL fatal errors
73
- * 2 - LOG_LEVEL_ERROR all errors
74
- * 3 - LOG_LEVEL_WARNING errors, and warnings
75
- * 4 - LOG_LEVEL_NOTICE errors, warnings and notices
71
+ * 0 - LOG_LEVEL_SILENT no output
72
+ * 1 - LOG_LEVEL_FATAL fatal errors
73
+ * 2 - LOG_LEVEL_ERROR all errors
74
+ * 3 - LOG_LEVEL_WARNING errors and warnings
75
+ * 4 - LOG_LEVEL_NOTICE errors, warnings and notices
76
76
* 5 - LOG_LEVEL_TRACE errors, warnings, notices, traces
77
- * 6 - LOG_LEVEL_VERBOSE all
77
+ * 6 - LOG_LEVEL_VERBOSE all
78
78
*/
79
79
80
80
class Logging {
@@ -83,14 +83,14 @@ class Logging {
83
83
bool _showLevel;
84
84
Print* _logOutput;
85
85
public:
86
- /* !
86
+ /* !
87
87
* default Constructor
88
88
*/
89
89
Logging ()
90
90
: _level(LOG_LEVEL_SILENT),
91
91
_showLevel (true ),
92
92
_logOutput(NULL ) {}
93
-
93
+
94
94
95
95
/* *
96
96
* Initializing, must be called as first. Note that if you use
@@ -104,124 +104,130 @@ class Logging {
104
104
void begin (int level, Print *output, bool showLevel = true );
105
105
106
106
/* *
107
- * Output an error message. Output message contains
108
- * ERROR: followed by original msg
109
- * Error messages are printed out, at every loglevel
110
- * except 0 ;-)
107
+ * Output a fatal error message. Output message contains
108
+ * F: followed by original message
109
+ * Fatal error messages are printed out at
110
+ * loglevels >= LOG_LEVEL_FATAL
111
+ *
111
112
* \param msg format string to output
112
113
* \param ... any number of variables
113
114
* \return void
114
115
*/
115
116
template <class T > void fatal (T msg, ...){
116
- #ifndef DISABLE_LOGGING
117
+ #ifndef DISABLE_LOGGING
117
118
if (LOG_LEVEL_FATAL <= _level) {
118
119
if (_showLevel) _logOutput->print (" F: " );
119
120
va_list args;
120
121
va_start (args, msg);
121
122
print (msg,args);
122
123
}
123
- #endif
124
+ #endif
124
125
}
125
-
126
+
126
127
/* *
127
128
* Output an error message. Output message contains
128
- * ERROR: followed by original msg
129
- * Error messages are printed out, at every loglevel
130
- * except 0 ;-)
129
+ * E: followed by original message
130
+ * Error messages are printed out at
131
+ * loglevels >= LOG_LEVEL_ERROR
132
+ *
131
133
* \param msg format string to output
132
134
* \param ... any number of variables
133
135
* \return void
134
136
*/
135
137
template <class T > void error (T msg, ...){
136
- #ifndef DISABLE_LOGGING
138
+ #ifndef DISABLE_LOGGING
137
139
if (LOG_LEVEL_ERROR <= _level) {
138
140
if (_showLevel) _logOutput->print (" E: " );
139
141
va_list args;
140
142
va_start (args, msg);
141
143
print (msg,args);
142
144
}
143
- #endif
145
+ #endif
144
146
}
145
147
/* *
146
- * Output an info message. Output message contains
147
- * Info messages are printed out at l
148
- * loglevels >= LOG_LEVEL_INFOS
148
+ * Output a warning message. Output message contains
149
+ * W: followed by original message
150
+ * Warning messages are printed out at
151
+ * loglevels >= LOG_LEVEL_WARNING
149
152
*
150
153
* \param msg format string to output
151
154
* \param ... any number of variables
152
155
* \return void
153
156
*/
154
157
155
158
template <class T > void warning (T msg, ...){
156
- #ifndef DISABLE_LOGGING
159
+ #ifndef DISABLE_LOGGING
157
160
if (LOG_LEVEL_WARNING <= _level) {
158
161
if (_showLevel) _logOutput->print (" W: " );
159
162
va_list args;
160
163
va_start (args, msg);
161
164
print (msg,args);
162
165
}
163
- #endif
166
+ #endif
164
167
}
165
168
/* *
166
- * Output an debug message. Output message contains
167
- * Debug messages are printed out at l
168
- * loglevels >= LOG_LEVEL_DEBUG
169
+ * Output a notice message. Output message contains
170
+ * N: followed by original message
171
+ * Notice messages are printed out at
172
+ * loglevels >= LOG_LEVEL_NOTICE
169
173
*
170
174
* \param msg format string to output
171
175
* \param ... any number of variables
172
176
* \return void
173
177
*/
174
178
175
179
template <class T > void notice (T msg, ...){
176
- #ifndef DISABLE_LOGGING
180
+ #ifndef DISABLE_LOGGING
177
181
if (LOG_LEVEL_NOTICE <= _level) {
178
182
if (_showLevel) _logOutput->print (" N: " );
179
183
va_list args;
180
184
va_start (args, msg);
181
185
print (msg,args);
182
186
}
183
- #endif
187
+ #endif
184
188
}
185
189
/* *
186
190
* Output a trace message. Output message contains
187
- * Debug messages are printed out at l
188
- * loglevels >= LOG_LEVEL_VERBOSE
191
+ * N: followed by original message
192
+ * Trace messages are printed out at
193
+ * loglevels >= LOG_LEVEL_TRACE
189
194
*
190
195
* \param msg format string to output
191
196
* \param ... any number of variables
192
197
* \return void
193
198
*/
194
199
template <class T > void trace (T msg, ...){
195
- #ifndef DISABLE_LOGGING
200
+ #ifndef DISABLE_LOGGING
196
201
if (LOG_LEVEL_TRACE <= _level) {
197
202
if (_showLevel) _logOutput->print (" T: " );
198
203
va_list args;
199
204
va_start (args, msg);
200
205
print (msg,args);
201
206
}
202
- #endif
203
- }
204
-
207
+ #endif
208
+ }
209
+
205
210
/* *
206
- * Output an verbose message. Output message contains
207
- * Debug messages are printed out at l
211
+ * Output a verbose message. Output message contains
212
+ * V: followed by original message
213
+ * Debug messages are printed out at
208
214
* loglevels >= LOG_LEVEL_VERBOSE
209
215
*
210
216
* \param msg format string to output
211
217
* \param ... any number of variables
212
218
* \return void
213
219
*/
214
220
template <class T > void verbose (T msg, ...){
215
- #ifndef DISABLE_LOGGING
221
+ #ifndef DISABLE_LOGGING
216
222
if (LOG_LEVEL_VERBOSE <= _level) {
217
223
if (_showLevel) _logOutput->print (" V: " );
218
224
va_list args;
219
225
va_start (args, msg);
220
226
print (msg,args);
221
227
}
222
- #endif
228
+ #endif
223
229
}
224
-
230
+
225
231
private:
226
232
void print (const char *format, va_list args);
227
233
void print (const __FlashStringHelper *format, va_list args);
@@ -231,6 +237,3 @@ class Logging {
231
237
extern Logging Log;
232
238
#endif
233
239
234
-
235
-
236
-
0 commit comments