log.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_LOG_H
  3. #define NETDATA_LOG_H 1
  4. # ifdef __cplusplus
  5. extern "C" {
  6. # endif
  7. #include "../libnetdata.h"
  8. #define D_WEB_BUFFER 0x0000000000000001
  9. #define D_WEB_CLIENT 0x0000000000000002
  10. #define D_LISTENER 0x0000000000000004
  11. #define D_WEB_DATA 0x0000000000000008
  12. #define D_OPTIONS 0x0000000000000010
  13. #define D_PROCNETDEV_LOOP 0x0000000000000020
  14. #define D_RRD_STATS 0x0000000000000040
  15. #define D_WEB_CLIENT_ACCESS 0x0000000000000080
  16. #define D_TC_LOOP 0x0000000000000100
  17. #define D_DEFLATE 0x0000000000000200
  18. #define D_CONFIG 0x0000000000000400
  19. #define D_PLUGINSD 0x0000000000000800
  20. #define D_CHILDS 0x0000000000001000
  21. #define D_EXIT 0x0000000000002000
  22. #define D_CHECKS 0x0000000000004000
  23. #define D_NFACCT_LOOP 0x0000000000008000
  24. #define D_PROCFILE 0x0000000000010000
  25. #define D_RRD_CALLS 0x0000000000020000
  26. #define D_DICTIONARY 0x0000000000040000
  27. #define D_MEMORY 0x0000000000080000
  28. #define D_CGROUP 0x0000000000100000
  29. #define D_REGISTRY 0x0000000000200000
  30. #define D_VARIABLES 0x0000000000400000
  31. #define D_HEALTH 0x0000000000800000
  32. #define D_CONNECT_TO 0x0000000001000000
  33. #define D_RRDHOST 0x0000000002000000
  34. #define D_LOCKS 0x0000000004000000
  35. #define D_EXPORTING 0x0000000008000000
  36. #define D_STATSD 0x0000000010000000
  37. #define D_POLLFD 0x0000000020000000
  38. #define D_STREAM 0x0000000040000000
  39. #define D_ANALYTICS 0x0000000080000000
  40. #define D_RRDENGINE 0x0000000100000000
  41. #define D_ACLK 0x0000000200000000
  42. #define D_METADATALOG 0x0000000400000000
  43. #define D_ACLK_SYNC 0x0000000800000000
  44. #define D_META_SYNC 0x0000001000000000
  45. #define D_REPLICATION 0x0000002000000000
  46. #define D_SYSTEM 0x8000000000000000
  47. extern int web_server_is_multithreaded;
  48. extern uint64_t debug_flags;
  49. extern const char *program_name;
  50. extern int stdaccess_fd;
  51. extern FILE *stdaccess;
  52. extern int stdhealth_fd;
  53. extern FILE *stdhealth;
  54. extern int stdcollector_fd;
  55. extern FILE *stderror;
  56. extern const char *stdaccess_filename;
  57. extern const char *stderr_filename;
  58. extern const char *stdout_filename;
  59. extern const char *stdhealth_filename;
  60. extern const char *stdcollector_filename;
  61. extern const char *facility_log;
  62. #ifdef ENABLE_ACLK
  63. extern const char *aclklog_filename;
  64. extern int aclklog_fd;
  65. extern FILE *aclklog;
  66. extern int aclklog_enabled;
  67. #endif
  68. extern int access_log_syslog;
  69. extern int error_log_syslog;
  70. extern int output_log_syslog;
  71. extern int health_log_syslog;
  72. extern time_t error_log_throttle_period;
  73. extern unsigned long error_log_errors_per_period, error_log_errors_per_period_backup;
  74. int error_log_limit(int reset);
  75. void open_all_log_files();
  76. void reopen_all_log_files();
  77. #define LOG_DATE_LENGTH 26
  78. void log_date(char *buffer, size_t len, time_t now);
  79. static inline void debug_dummy(void) {}
  80. void error_log_limit_reset(void);
  81. void error_log_limit_unlimited(void);
  82. typedef struct error_with_limit {
  83. time_t log_every;
  84. size_t count;
  85. time_t last_logged;
  86. usec_t sleep_ut;
  87. } ERROR_LIMIT;
  88. #define error_limit_static_global_var(var, log_every_secs, sleep_usecs) static ERROR_LIMIT var = { .last_logged = 0, .count = 0, .log_every = (log_every_secs), .sleep_ut = (sleep_usecs) }
  89. #define error_limit_static_thread_var(var, log_every_secs, sleep_usecs) static __thread ERROR_LIMIT var = { .last_logged = 0, .count = 0, .log_every = (log_every_secs), .sleep_ut = (sleep_usecs) }
  90. #ifdef NETDATA_INTERNAL_CHECKS
  91. #define debug(type, args...) do { if(unlikely(debug_flags & type)) debug_int(__FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
  92. #define internal_error(condition, args...) do { if(unlikely(condition)) error_int(0, "IERR", __FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
  93. #define internal_fatal(condition, args...) do { if(unlikely(condition)) fatal_int(__FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
  94. #else
  95. #define debug(type, args...) debug_dummy()
  96. #define internal_error(args...) debug_dummy()
  97. #define internal_fatal(args...) debug_dummy()
  98. #endif
  99. #define info(args...) info_int(0, __FILE__, __FUNCTION__, __LINE__, ##args)
  100. #define collector_info(args...) info_int(1, __FILE__, __FUNCTION__, __LINE__, ##args)
  101. #define infoerr(args...) error_int(0, "INFO", __FILE__, __FUNCTION__, __LINE__, ##args)
  102. #define error(args...) error_int(0, "ERROR", __FILE__, __FUNCTION__, __LINE__, ##args)
  103. #define collector_infoerr(args...) error_int(1, "INFO", __FILE__, __FUNCTION__, __LINE__, ##args)
  104. #define collector_error(args...) error_int(1, "ERROR", __FILE__, __FUNCTION__, __LINE__, ##args)
  105. #define error_limit(erl, args...) error_limit_int(erl, "ERROR", __FILE__, __FUNCTION__, __LINE__, ##args)
  106. #define fatal(args...) fatal_int(__FILE__, __FUNCTION__, __LINE__, ##args)
  107. #define fatal_assert(expr) ((expr) ? (void)(0) : fatal_int(__FILE__, __FUNCTION__, __LINE__, "Assertion `%s' failed", #expr))
  108. void send_statistics(const char *action, const char *action_result, const char *action_data);
  109. void debug_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) PRINTFLIKE(4, 5);
  110. void info_int( int is_collector, const char *file, const char *function, const unsigned long line, const char *fmt, ... ) PRINTFLIKE(5, 6);
  111. void error_int( int is_collector, const char *prefix, const char *file, const char *function, const unsigned long line, const char *fmt, ... ) PRINTFLIKE(6, 7);
  112. void error_limit_int(ERROR_LIMIT *erl, const char *prefix, const char *file __maybe_unused, const char *function __maybe_unused, unsigned long line __maybe_unused, const char *fmt, ... ) PRINTFLIKE(6, 7);;
  113. void fatal_int( const char *file, const char *function, const unsigned long line, const char *fmt, ... ) NORETURN PRINTFLIKE(4, 5);
  114. void log_access( const char *fmt, ... ) PRINTFLIKE(1, 2);
  115. void log_health( const char *fmt, ... ) PRINTFLIKE(1, 2);
  116. #ifdef ENABLE_ACLK
  117. void log_aclk_message_bin( const char *data, const size_t data_len, int tx, const char *mqtt_topic, const char *message_name);
  118. #endif
  119. # ifdef __cplusplus
  120. }
  121. # endif
  122. #endif /* NETDATA_LOG_H */