snmp_logging.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef SNMP_LOGGING_H
  2. #define SNMP_LOGGING_H
  3. #include <net-snmp/types.h>
  4. #include <net-snmp/output_api.h>
  5. #ifdef HAVE_SYSLOG_H
  6. #include <syslog.h>
  7. #endif
  8. #include <stdio.h>
  9. #include <stdarg.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #ifndef LOG_ERR
  14. #define LOG_EMERG 0 /* system is unusable */
  15. #define LOG_ALERT 1 /* action must be taken immediately */
  16. #define LOG_CRIT 2 /* critical conditions */
  17. #define LOG_ERR 3 /* error conditions */
  18. #define LOG_WARNING 4 /* warning conditions */
  19. #define LOG_NOTICE 5 /* normal but significant condition */
  20. #define LOG_INFO 6 /* informational */
  21. #define LOG_DEBUG 7 /* debug-level messages */
  22. #endif
  23. struct snmp_log_message {
  24. int priority;
  25. const char *msg;
  26. };
  27. #ifndef DEFAULT_LOG_ID
  28. #define DEFAULT_LOG_ID "net-snmp"
  29. #endif
  30. #define NETSNMP_LOGONCE(x) do { \
  31. static char logged = 0; \
  32. if (!logged) { \
  33. logged = 1; \
  34. snmp_log x ; \
  35. } \
  36. } while(0)
  37. void init_snmp_logging(void);
  38. NETSNMP_IMPORT
  39. void snmp_disable_syslog(void);
  40. void snmp_disable_filelog(void);
  41. NETSNMP_IMPORT
  42. void snmp_disable_stderrlog(void);
  43. void snmp_disable_calllog(void);
  44. NETSNMP_IMPORT
  45. void snmp_enable_syslog(void);
  46. NETSNMP_IMPORT
  47. void snmp_enable_syslog_ident(const char *ident,
  48. const int facility);
  49. NETSNMP_IMPORT
  50. void snmp_enable_filelog(const char *logfilename,
  51. int dont_zero_log);
  52. NETSNMP_IMPORT
  53. void snmp_enable_stderrlog(void);
  54. NETSNMP_IMPORT
  55. void snmp_enable_calllog(void);
  56. NETSNMP_IMPORT
  57. int snmp_stderrlog_status(void);
  58. #define NETSNMP_LOGHANDLER_STDOUT 1
  59. #define NETSNMP_LOGHANDLER_STDERR 2
  60. #define NETSNMP_LOGHANDLER_FILE 3
  61. #define NETSNMP_LOGHANDLER_SYSLOG 4
  62. #define NETSNMP_LOGHANDLER_CALLBACK 5
  63. #define NETSNMP_LOGHANDLER_NONE 6
  64. NETSNMP_IMPORT
  65. void netsnmp_set_line_buffering(FILE *stream);
  66. NETSNMP_IMPORT
  67. int snmp_log_options(char *optarg, int argc, char *const *argv);
  68. NETSNMP_IMPORT
  69. void snmp_log_options_usage(const char *lead, FILE *outf);
  70. NETSNMP_IMPORT
  71. char *snmp_log_syslogname(const char *syslogname);
  72. typedef struct netsnmp_log_handler_s netsnmp_log_handler;
  73. typedef int (NetsnmpLogHandler)(netsnmp_log_handler*, int, const char *);
  74. #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_STDIO
  75. NetsnmpLogHandler log_handler_stdouterr;
  76. #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_STDIO */
  77. NetsnmpLogHandler log_handler_file;
  78. NetsnmpLogHandler log_handler_syslog;
  79. NetsnmpLogHandler log_handler_callback;
  80. NetsnmpLogHandler log_handler_null;
  81. struct netsnmp_log_handler_s {
  82. int enabled;
  83. int priority;
  84. int pri_max;
  85. int type;
  86. const char *token; /* Also used for filename */
  87. NetsnmpLogHandler *handler;
  88. int imagic; /* E.g. file descriptor, syslog facility */
  89. void *magic; /* E.g. Callback function */
  90. netsnmp_log_handler *next, *prev;
  91. };
  92. NETSNMP_IMPORT
  93. netsnmp_log_handler *get_logh_head( void );
  94. NETSNMP_IMPORT
  95. netsnmp_log_handler *netsnmp_register_loghandler( int type, int pri );
  96. netsnmp_log_handler *netsnmp_find_loghandler( const char *token );
  97. int netsnmp_add_loghandler( netsnmp_log_handler *logh );
  98. NETSNMP_IMPORT
  99. int netsnmp_remove_loghandler( netsnmp_log_handler *logh );
  100. int netsnmp_enable_loghandler( const char *token );
  101. int netsnmp_disable_loghandler( const char *token );
  102. NETSNMP_IMPORT
  103. void netsnmp_enable_this_loghandler( netsnmp_log_handler *logh );
  104. NETSNMP_IMPORT
  105. void netsnmp_disable_this_loghandler( netsnmp_log_handler *logh );
  106. NETSNMP_IMPORT
  107. void netsnmp_logging_restart(void);
  108. NETSNMP_IMPORT
  109. netsnmp_log_handler *
  110. netsnmp_create_stdio_loghandler(int is_stdout, int priority, int priority_max,
  111. const char *tok);
  112. NETSNMP_IMPORT
  113. netsnmp_log_handler *
  114. netsnmp_register_filelog_handler(const char* logfilename, int priority,
  115. int priority_max, int dont_zero_log);
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* SNMP_LOGGING_H */