Пример #1
0
bool qd_entity_opt_bool(qd_entity_t *entity, const char* attribute, bool default_value) {
    if (qd_entity_has(entity, attribute)) {
        bool result = qd_entity_get_bool(entity, attribute);
        if (!qd_error_code())
            return result;
    }
    return default_value;
}
Пример #2
0
qd_error_t qd_log_entity(qd_entity_t *entity) {

    qd_error_clear();
    char* module = qd_entity_get_string(entity, "module"); QD_ERROR_RET();
    sys_mutex_lock(log_source_lock);
    qd_log_source_t *src = qd_log_source_lh(module); /* The original log source */
    free(module);
    qd_log_source_t copy = *src; /* A copy to modify outside the lock. */
    sys_mutex_unlock(log_source_lock);

    if (qd_entity_has(entity, "enable")) {
        char *enable = qd_entity_get_string(entity, "enable");
        copy.mask = enable_mask(enable);
        free(enable);
    }
    QD_ERROR_RET();

    if (qd_entity_has(entity, "timestamp"))
        copy.timestamp = qd_entity_get_bool(entity, "timestamp");
    QD_ERROR_RET();

    if (qd_entity_has(entity, "source"))
        copy.source = qd_entity_get_bool(entity, "source");
    QD_ERROR_RET();

    if (qd_entity_has(entity, "output")) {
         log_sink_free_lh(copy.sink); /* DEFAULT source may already have a sink */
        char* output = qd_entity_get_string(entity, "output"); QD_ERROR_RET();
        copy.sink = log_sink_lh(output);
        free(output);
        if (copy.sink->syslog) /* Timestamp off for syslog. */
            copy.timestamp = 0;
    }

    sys_mutex_lock(log_source_lock);
    *src = copy;
    sys_mutex_unlock(log_source_lock);
    return qd_error_code();
}