logging.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2012 zefir
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #ifndef __LOGGING_H__
  10. #define __LOGGING_H__
  11. #include "config.h"
  12. #include <stdbool.h>
  13. #include <stdarg.h>
  14. #ifdef HAVE_SYSLOG_H
  15. #include <syslog.h>
  16. #else
  17. enum {
  18. LOG_ERR,
  19. LOG_WARNING,
  20. LOG_NOTICE,
  21. LOG_INFO,
  22. LOG_DEBUG,
  23. };
  24. #endif
  25. /* original / legacy debug flags */
  26. extern bool opt_debug;
  27. extern bool opt_debug_console;
  28. extern bool opt_log_output;
  29. extern bool opt_realquiet;
  30. extern bool want_per_device_stats;
  31. /* global log_level, messages with lower or equal prio are logged */
  32. extern int opt_log_level;
  33. /* low-level logging functions with priority parameter */
  34. extern void vapplog(int prio, const char *fmt, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
  35. extern void applog(int prio, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
  36. #define applogr(rv, prio, ...) do { \
  37. applog(prio, __VA_ARGS__); \
  38. return rv; \
  39. } while (0)
  40. /* high-level logging functions with implicit priority */
  41. extern void log_error(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  42. extern void log_warning(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  43. extern void log_notice(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  44. extern void log_info(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  45. extern void log_debug(const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  46. extern void hexdump(const void *, unsigned int len);
  47. #endif /* __LOGGING_H__ */