logging.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef __LOGGING_H__
  2. #define __LOGGING_H__
  3. #include "config.h"
  4. #include <stdbool.h>
  5. #include <stdarg.h>
  6. #ifdef HAVE_SYSLOG_H
  7. #include <syslog.h>
  8. #else
  9. enum {
  10. LOG_ERR,
  11. LOG_WARNING,
  12. LOG_NOTICE,
  13. LOG_INFO,
  14. LOG_DEBUG,
  15. };
  16. #endif
  17. /* debug flags */
  18. extern bool opt_debug;
  19. extern bool opt_log_output;
  20. extern bool opt_realquiet;
  21. extern bool want_per_device_stats;
  22. /* global log_level, messages with lower or equal prio are logged */
  23. extern int opt_log_level;
  24. #define LOGBUFSIZ 0x1000
  25. extern void _applog(int prio, const char *str);
  26. #define applog(prio, fmt, ...) do { \
  27. if (opt_debug || prio != LOG_DEBUG) { \
  28. if (use_syslog || opt_log_output || prio <= opt_log_level) { \
  29. char tmp42[LOGBUFSIZ]; \
  30. snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
  31. _applog(prio, tmp42); \
  32. } \
  33. } \
  34. } while (0)
  35. #define quit(status, fmt, ...) do { \
  36. if (fmt) { \
  37. char tmp42[LOGBUFSIZ]; \
  38. snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
  39. _applog(LOG_ERR, tmp42); \
  40. } \
  41. _quit(status); \
  42. } while (0)
  43. #ifdef HAVE_CURSES
  44. #define wlog(fmt, ...) do { \
  45. char tmp42[LOGBUFSIZ]; \
  46. snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
  47. _wlog(tmp42); \
  48. } while (0)
  49. #define wlogprint(fmt, ...) do { \
  50. char tmp42[LOGBUFSIZ]; \
  51. snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
  52. _wlogprint(tmp42); \
  53. } while (0)
  54. #endif
  55. #endif /* __LOGGING_H__ */