Statistics
| Branch: | Revision:

ml / ml_log.h @ 6575ae37

History | View | Annotate | Download (967 Bytes)

1
#ifndef _ML_LOG_H
2
#define _ML_LOG_H
3

    
4
#include <stdlib.h>
5
#include <stdio.h>
6

    
7
extern int ml_log_level;
8

    
9
extern void setLogLevel(int ll);
10

    
11
#define DPRINT(ll, format, ... )  {struct timeval tnow; if(ll <= ml_log_level) {gettimeofday(&tnow,NULL); fprintf(stderr, "%ld.%03ld "format, tnow.tv_sec, tnow.tv_usec/1000, ##__VA_ARGS__ );fprintf(stderr,format[strlen(format)-1] == '\n'?"":"\n"); fflush(stderr);}}
12

    
13
#define debug(format, ... ) DPRINT(4 ,format, ##__VA_ARGS__ )
14
/** Convenience macro to log LOG_INFO messages */
15
#define info(format, ... )  DPRINT(3, format, ##__VA_ARGS__ )
16
/** Convenience macro to log LOG_WARN messages */
17
#define warn(format, ... )  DPRINT(2, format, ##__VA_ARGS__ )
18
/** Convenience macro to log LOG_ERROR messages */
19
#define error(format, ... )  DPRINT(1, format, ##__VA_ARGS__ )
20
/**  Convenience macro to log LOG_CRITICAL messages and crash the program */
21
#define fatal(format, ... )  { DPRINT(0, format, ##__VA_ARGS__ ); exit(-1); }
22

    
23
#endif