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