Beispiel #1
0
netsnmp_log_handler *
netsnmp_register_loghandler( int type, int priority )
{
    netsnmp_log_handler *logh;

    logh = SNMP_MALLOC_TYPEDEF(netsnmp_log_handler);
    if (!logh)
        return NULL;

    DEBUGMSGT(("logging:register", "registering log type %d with pri %d\n",
               type, priority));
    if (priority > LOG_DEBUG) {
        DEBUGMSGT(("logging:register", "  limiting pri %d to %d\n", priority,
                   LOG_DEBUG));
        priority = LOG_DEBUG;
    }

    logh->type     = type;
    switch ( type ) {
    case NETSNMP_LOGHANDLER_STDOUT:
        logh->imagic  = 1;
        logh->handler = log_handler_stdouterr;
        break;
#ifndef NETSNMP_FEATURE_REMOVE_LOGGING_STDIO
    case NETSNMP_LOGHANDLER_STDERR:
        logh->handler = log_handler_stdouterr;
        break;
#endif /* NETSNMP_FEATURE_REMOVE_LOGGING_STDIO */

#ifndef NETSNMP_FEATURE_REMOVE_LOGGING_FILE
    case NETSNMP_LOGHANDLER_FILE:
        logh->handler = log_handler_file;
        logh->imagic  = 1;
        break;
#endif /* NETSNMP_FEATURE_REMOVE_LOGGING_FILE */
#ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG
    case NETSNMP_LOGHANDLER_SYSLOG:
        logh->handler = log_handler_syslog;
        break;
#endif /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */
    case NETSNMP_LOGHANDLER_CALLBACK:
        logh->handler = log_handler_callback;
        break;
    case NETSNMP_LOGHANDLER_NONE:
        logh->handler = log_handler_null;
        break;
    default:
        free(logh);
        return NULL;
    }
    logh->priority = priority;
    netsnmp_enable_this_loghandler(logh);
    netsnmp_add_loghandler( logh );
    return logh;
}
netsnmp_log_handler *
netsnmp_register_loghandler( int type, int priority )
{
    netsnmp_log_handler *logh;

    logh = SNMP_MALLOC_TYPEDEF(netsnmp_log_handler);
    if (!logh)
        return NULL;

    DEBUGMSGT(("logging:register", "registering log type %d with pri %d\n",
               type, priority));

    logh->type     = type;
    switch ( type ) {
    case NETSNMP_LOGHANDLER_STDOUT:
        logh->imagic  = 1;
        /* fallthrough */
    case NETSNMP_LOGHANDLER_STDERR:
        logh->handler = log_handler_stdouterr;
        break;

    case NETSNMP_LOGHANDLER_FILE:
        logh->handler = log_handler_file;
        logh->imagic  = 1;
        break;
    case NETSNMP_LOGHANDLER_SYSLOG:
        logh->handler = log_handler_syslog;
        break;
    case NETSNMP_LOGHANDLER_CALLBACK:
        logh->handler = log_handler_callback;
        break;
    case NETSNMP_LOGHANDLER_NONE:
        logh->handler = log_handler_null;
        break;
    default:
        free(logh);
        return NULL;
    }
    logh->priority = priority;
    netsnmp_enable_this_loghandler(logh);
    netsnmp_add_loghandler( logh );
    return logh;
}