net-snmp 5.7
snmp_logging.h
00001 #ifndef SNMP_LOGGING_H
00002 #define SNMP_LOGGING_H
00003 
00004 #include <net-snmp/types.h>
00005 #include <net-snmp/output_api.h>
00006 
00007 #if HAVE_SYSLOG_H
00008 #include <syslog.h>
00009 #endif
00010 #include <stdio.h>
00011 #include <stdarg.h>
00012 
00013 #ifdef __cplusplus
00014 extern          "C" {
00015 #endif
00016 
00017 #ifndef LOG_ERR
00018 #define LOG_EMERG       0       /* system is unusable */
00019 #define LOG_ALERT       1       /* action must be taken immediately */
00020 #define LOG_CRIT        2       /* critical conditions */
00021 #define LOG_ERR         3       /* error conditions */
00022 #define LOG_WARNING     4       /* warning conditions */
00023 #define LOG_NOTICE      5       /* normal but significant condition */
00024 #define LOG_INFO        6       /* informational */
00025 #define LOG_DEBUG       7       /* debug-level messages */
00026 #endif
00027 
00028     struct snmp_log_message {
00029         int             priority;
00030         const char     *msg;
00031     };
00032 
00033 #ifndef DEFAULT_LOG_ID
00034 #define DEFAULT_LOG_ID "net-snmp"
00035 #endif
00036 
00037 #define NETSNMP_LOGONCE(x) do { \
00038         static char logged = 0; \
00039         if (!logged) {          \
00040             logged = 1;         \
00041             snmp_log x ;        \
00042         }                       \
00043     } while(0)
00044 
00045     void            init_snmp_logging(void);
00046     NETSNMP_IMPORT
00047     void            snmp_disable_syslog(void);
00048     void            snmp_disable_filelog(void);
00049     NETSNMP_IMPORT
00050     void            snmp_disable_stderrlog(void);
00051     void            snmp_disable_calllog(void);
00052     NETSNMP_IMPORT
00053     void            snmp_enable_syslog(void);
00054     NETSNMP_IMPORT
00055     void            snmp_enable_syslog_ident(const char *ident,
00056                                              const int   facility);
00057     NETSNMP_IMPORT
00058     void            snmp_enable_filelog(const char *logfilename,
00059                                         int dont_zero_log);
00060     NETSNMP_IMPORT
00061     void            snmp_enable_stderrlog(void);
00062     void            snmp_enable_calllog(void);
00063 
00064     NETSNMP_IMPORT
00065     int             snmp_stderrlog_status(void);
00066 
00067 
00068 #define NETSNMP_LOGHANDLER_STDOUT       1
00069 #define NETSNMP_LOGHANDLER_STDERR       2
00070 #define NETSNMP_LOGHANDLER_FILE         3
00071 #define NETSNMP_LOGHANDLER_SYSLOG       4
00072 #define NETSNMP_LOGHANDLER_CALLBACK     5
00073 #define NETSNMP_LOGHANDLER_NONE         6
00074 
00075     NETSNMP_IMPORT
00076     void netsnmp_set_line_buffering(FILE *stream);
00077     NETSNMP_IMPORT
00078     int snmp_log_options(char *optarg, int argc, char *const *argv);
00079     NETSNMP_IMPORT
00080     void snmp_log_options_usage(const char *lead, FILE *outf);
00081     NETSNMP_IMPORT
00082     char *snmp_log_syslogname(const char *syslogname);
00083     typedef struct netsnmp_log_handler_s netsnmp_log_handler; 
00084     typedef int (NetsnmpLogHandler)(netsnmp_log_handler*, int, const char *);
00085 
00086     NetsnmpLogHandler log_handler_stdouterr;
00087     NetsnmpLogHandler log_handler_file;
00088     NetsnmpLogHandler log_handler_syslog;
00089     NetsnmpLogHandler log_handler_callback;
00090     NetsnmpLogHandler log_handler_null;
00091 
00092     struct netsnmp_log_handler_s {
00093         int     enabled;
00094         int     priority;
00095         int     pri_max;
00096         int     type;
00097         const char *token;              /* Also used for filename */
00098 
00099         NetsnmpLogHandler       *handler;
00100 
00101         int     imagic;         /* E.g. file descriptor, syslog facility */
00102         void   *magic;          /* E.g. Callback function */
00103 
00104         netsnmp_log_handler     *next, *prev;
00105     };
00106 
00107 NETSNMP_IMPORT
00108 netsnmp_log_handler *get_logh_head( void );
00109 NETSNMP_IMPORT
00110 netsnmp_log_handler *netsnmp_register_loghandler( int type, int pri );
00111 netsnmp_log_handler *netsnmp_find_loghandler( const char *token );
00112 int netsnmp_add_loghandler(    netsnmp_log_handler *logh );
00113 NETSNMP_IMPORT
00114 int netsnmp_remove_loghandler( netsnmp_log_handler *logh );
00115 int netsnmp_enable_loghandler( const char *token );
00116 int netsnmp_disable_loghandler( const char *token );
00117 NETSNMP_IMPORT
00118 void netsnmp_enable_this_loghandler( netsnmp_log_handler *logh );
00119 NETSNMP_IMPORT
00120 void netsnmp_disable_this_loghandler( netsnmp_log_handler *logh );
00121 NETSNMP_IMPORT
00122 void netsnmp_logging_restart(void);
00123 #ifdef __cplusplus
00124 }
00125 #endif
00126 #endif                          /* SNMP_LOGGING_H */