AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
log.h
1 
18 #ifndef _AVRIO_LOG_H_
19 #define _AVRIO_LOG_H_
20 #include <avrio/defs.h>
21 __BEGIN_C_DECLS
22 /* ========================================================================== */
31 /* constants ================================================================ */
32 #define LOG_EMERG 3
33 #define LOG_ALERT 3
34 #define LOG_CRIT 3
35 #define LOG_ERR 3
36 #define LOG_WARNING 4
37 #define LOG_NOTICE 5
38 #define LOG_INFO 6
39 #define LOG_DEBUG 7
41 # if defined(__DOXYGEN__)
42 /*
43  * __DOXYGEN__ defined
44  * Partie documentation ne devant pas être compilée.
45  * =============================================================================
46  */
47 /* macros =================================================================== */
51 #define LOG_MASK(p)
52 
56 #define LOG_UPTO(p)
57 
69 #define PDEBUG(fmt,...)
70 
81 #define PINFO(fmt,...)
82 
93 #define PNOTICE(fmt,...)
94 
105 #define PWARNING(fmt,...)
106 
117 #define PERROR(fmt,...)
118 
119 /* internal public functions ================================================ */
132 void vLog (int priority, const char *format, ...);
133 
146 void vLog_P (int priority, const char *format, ...);
147 
154 const char * sLogPriorityString (int priority);
155 
167 static inline void vLogSetMask (int mask);
168 
176 static inline int iLogMask (void);
177 
185 static inline void vLogSetFile (FILE * f);
186 
194 static inline FILE * pxLogFile (void);
195 
200 # else
201 /*
202  * __DOXYGEN__ not defined
203  * Partie ne devant pas être documentée.
204  * =============================================================================
205  */
206 
207 /* macros =================================================================== */
208 
209 /* Macros de compatibilité SysIO ne faisant rien */
210 #define __progname ""
211 #define vLogInit (m)
212 #define vLogDaemonize (d)
213 #define bLogIsDaemonized() (0)
214 #define LOG_MASK(p) (1<<((p)&0x07))
215 #define LOG_UPTO(p) ((LOG_MASK(p) << 1) - 1)
216 
217 #ifndef NLOG
218 #include <stdio.h>
219 #include <avr/pgmspace.h>
220 
221 /* structures =============================================================== */
222 typedef struct xLog xLog;
223 struct xLog {
224 
225  FILE * stream;
226  int mask;
227 };
228 
229 /* public variables ========================================================= */
230 extern xLog xAvrioLog;
231 
232 /* macros =================================================================== */
233 
234 #define PERROR(fmt,...) vLog_P (LOG_ERR,PSTR("%s():%d: "fmt),\
235  __FUNCTION__, __LINE__,##__VA_ARGS__)
236 
237 #ifdef DEBUG
238 #define PDEBUG(fmt,...) vLog_P (LOG_DEBUG,PSTR("%s():%d: "fmt),\
239  __FUNCTION__, __LINE__,##__VA_ARGS__)
240 #define PINFO(fmt,...) vLog_P (LOG_INFO,PSTR("%s():%d: "fmt),\
241  __FUNCTION__, __LINE__,##__VA_ARGS__)
242 #define PNOTICE(fmt,...) vLog_P (LOG_NOTICE,PSTR("%s():%d: "fmt),\
243  __FUNCTION__, __LINE__,##__VA_ARGS__)
244 #define PWARNING(fmt,...) vLog_P (LOG_WARNING,PSTR("%s():%d: "fmt),\
245  __FUNCTION__, __LINE__,##__VA_ARGS__)
246 #else /* DEBUG not defined */
247 #define PDEBUG(fmt,...)
248 #define PINFO(fmt,...) vLog_P (LOG_INFO,PSTR(fmt),##__VA_ARGS__)
249 #define PNOTICE(fmt,...) vLog_P (LOG_NOTICE,PSTR(fmt),##__VA_ARGS__)
250 #define PWARNING(fmt,...) vLog_P (LOG_WARNING,PSTR(fmt),##__VA_ARGS__)
251 #endif /* DEBUG not defined */
252 
253 /* internal public functions ================================================ */
254 void vLog (int priority, const char *format, ...);
255 void vLog_P (int priority, const char *format, ...);
256 const char * sLogPriorityString (int priority);
257 
258 /* inline public functions ================================================== */
259 
260 // -----------------------------------------------------------------------------
261 INLINE void
262 vLogSetMask (int mask) {
263 
264  xAvrioLog.mask = mask;
265 }
266 
267 // -----------------------------------------------------------------------------
268 INLINE int
269 iLogMask (void) {
270 
271  return xAvrioLog.mask;
272 }
273 
274 // -----------------------------------------------------------------------------
275 INLINE void
276 vLogSetFile (FILE * f) {
277 
278  xAvrioLog.stream = f;
279 }
280 
281 // -----------------------------------------------------------------------------
282 INLINE FILE *
283 pxLogFile (void) {
284 
285  return (xAvrioLog.stream) ? xAvrioLog.stream : stderr;
286 }
287 
288 #else /* NLOG defined */
289 
290 /* macros =================================================================== */
291 #define PWARNING(fmt,...)
292 #define PERROR(fmt,...)
293 #define PINFO(fmt,...)
294 #define PNOTICE(fmt,...)
295 #define PDEBUG(fmt,...)
296 
297 /* internal public functions ================================================ */
298 #define vLog(p,fmt,...)
299 #define vLog_P(p,fmt,...)
300 #define sLogPriorityString(p) "Unsupported"
301 
302 /* inline public functions ================================================== */
303 #define vLogSetMask(m)
304 #define iLogMask() (-1)
305 #define vLogSetFile(f)
306 #define pxLogFile() (NULL)
307 
308 #endif /* NLOG defined */
309 
310 #endif /* __DOXYGEN__ not defined */
311 
312 /* ========================================================================== */
313 __END_C_DECLS
314 #endif /* _AVRIO_LOG_H_ */
static void vLogSetMask(int mask)
Fixe le masque des priorités.
static int iLogMask(void)
Lecture du masque des priorités en cours.
static void vLogSetFile(FILE *f)
Modifie le fichier de log.
void vLog_P(int priority, const char *format,...)
Affichage ou écriture d&#39;un message de log, version FLASH.
static FILE * pxLogFile(void)
Fichier de log courant.
void vLog(int priority, const char *format,...)
Affichage ou écriture d&#39;un message de log.
const char * sLogPriorityString(int priority)
Chaîne de caractère correspondant à la priorité