logger.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef TINC_LOGGER_H
  2. #define TINC_LOGGER_H
  3. /*
  4. logger.h -- header file for logger.c
  5. Copyright (C) 2003-2016 Guus Sliepen <guus@tinc-vpn.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with this program; if not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. typedef enum debug_t {
  19. DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
  20. DEBUG_ALWAYS = 0,
  21. DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
  22. DEBUG_ERROR = 2, /* Show error messages received from other hosts */
  23. DEBUG_STATUS = 2, /* Show status messages received from other hosts */
  24. DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
  25. DEBUG_META = 4, /* Show contents of every request that is sent/received */
  26. DEBUG_TRAFFIC = 5, /* Show network traffic information */
  27. DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
  28. DEBUG_SCARY_THINGS = 10, /* You have been warned */
  29. } debug_t;
  30. typedef enum logmode_t {
  31. LOGMODE_NULL,
  32. LOGMODE_STDERR,
  33. LOGMODE_FILE,
  34. LOGMODE_SYSLOG
  35. } logmode_t;
  36. #ifdef HAVE_MINGW
  37. #define LOG_EMERG EVENTLOG_ERROR_TYPE
  38. #define LOG_ALERT EVENTLOG_ERROR_TYPE
  39. #define LOG_CRIT EVENTLOG_ERROR_TYPE
  40. #define LOG_ERR EVENTLOG_ERROR_TYPE
  41. #define LOG_WARNING EVENTLOG_WARNING_TYPE
  42. #define LOG_NOTICE EVENTLOG_INFORMATION_TYPE
  43. #define LOG_INFO EVENTLOG_INFORMATION_TYPE
  44. #define LOG_DEBUG EVENTLOG_INFORMATION_TYPE
  45. #else
  46. #ifndef HAVE_SYSLOG_H
  47. enum {
  48. LOG_EMERG,
  49. LOG_ALERT,
  50. LOG_CRIT,
  51. LOG_ERR,
  52. LOG_WARNING,
  53. LOG_NOTICE,
  54. LOG_INFO,
  55. LOG_DEBUG,
  56. };
  57. #endif
  58. #endif
  59. extern debug_t debug_level;
  60. extern void openlogger(const char *ident, logmode_t mode);
  61. extern void reopenlogger(void);
  62. extern void logger(int priority, const char *format, ...) __attribute__((__format__(printf, 2, 3)));
  63. extern void closelogger(void);
  64. #define ifdebug(l) if(debug_level >= DEBUG_##l)
  65. #endif