Statistics
| Branch: | Revision:

napa-baselibs / include / napa_log.h @ 507372bb

History | View | Annotate | Download (2.61 KB)

1
#ifndef _NAPA_LOG_H
2
#define _NAPA_LOG_H
3

    
4
/** Logging facilities for NAPA 
5

6
 * @file napa_log.h
7
 * @brief This module provides convenient logging functions for other NAPA modules
8
 *
9
 */
10

    
11
#include        <stdlib.h>
12

    
13
/* These log levels should match dclog's internal definition */
14
#define DCLOG_ALARM   0 //!< alarms
15
#define DCLOG_ERROR   1 //!< error messages
16
#define DCLOG_WARNING 2 //!< warnings
17
#define DCLOG_INFO    3 //!< information messages
18
#define DCLOG_DEBUG   4 //!< debugging messages
19
#define DCLOG_PROFILE 5 //!< profiling messages
20

    
21
/** log level for CRITICAL messages */
22
#define LOG_CRITICAL    DCLOG_ALARM
23
/** log level for ERROR messages */
24
#define LOG_ERROR       DCLOG_ERROR
25
/** log level for WARNING messages */
26
#define LOG_WARN        DCLOG_WARNING
27
/** log level for INFO messages */
28
#define LOG_INFO        DCLOG_INFO
29
/** log level for DEBUG messages */
30
#define LOG_DEBUG       DCLOG_DEBUG
31
/** log level for PROFILE messages */
32
#define LOG_PROFILE     DCLOG_PROFILE
33

    
34
/** general-purpose, module-aware log facility, to be used with a log priority */
35
#define napa_log(priority, format, ... ) napaWriteLog(priority,  format " [%s,%d]\n",  ##__VA_ARGS__ , __FILE__, __LINE__ )
36
/** Convenience macro to log TODOs */
37
#define todo(format, ...) napa_log(LOG_WARN, "[TODO] " format " file: %s, line %d",  ##__VA_ARGS__ )
38

    
39
/** Convenience macro to log LOG_DEBUG messages */
40
#define debug(format, ... ) napa_log(LOG_DEBUG, format, ##__VA_ARGS__ )
41
/** Convenience macro to log LOG_INFO messages */
42
#define info(format, ... )  napa_log(LOG_INFO, format, ##__VA_ARGS__ )
43
/** Convenience macro to log LOG_WARN messages */
44
#define warn(format, ... )  napa_log(LOG_WARN, format, ##__VA_ARGS__ )
45
/** Convenience macro to log LOG_ERROR messages */
46
#define error(format, ... )  napa_log(LOG_ERROR, format, ##__VA_ARGS__ )
47
/**  Convenience macro to log LOG_CRITICAL messages and crash the program */
48
#define fatal(format, ... ) {  napa_log(LOG_CRITICAL, format, ##__VA_ARGS__ ); exit(-1); }
49

    
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53

    
54
/** 
55
  Initializes the NAPA logging facility.
56

57
  @param[in] loglevel Only log messages on or above this level
58
  @param[in] filename Write log messages to this file (might be "stderr" or "stdout")
59
  @param[in] mode file open mode ("a" for append or "w" for truncate)
60
*/
61
void napaInitLog(int loglevel, const char *filename, const char *mode);
62

    
63
/** Closes down NAPA logging facility. Log messages are discarded after this. */
64
void napaCloseLog();
65

    
66
/** Low-level interface to the NAPA logging system. Use the above defined convenience macros instead */
67
void napaWriteLog(const unsigned char lev, const char *fmt, ... );
68
#ifdef __cplusplus
69
}
70
#endif
71

    
72
#endif
73

    
74