Exemplo n.º 1
0
static int log_helper(log_t log, unsigned int level, const char *format,
                      va_list ap)
{
    static const char *level_strings[3] = {
        "",
        "Warning - ",
        "Error - "
    };

    const signed int logi = (signed int)log;
    int rc = 0;
    char *logtxt = NULL;

    if (!log_enabled) {
        return 0;
    }

    if ((logi != LOG_DEFAULT) && (logi != LOG_ERR)) {
        if ((logs == NULL) || (logi < 0)|| (logi >= num_logs) || (logs[logi] == NULL)) {
#ifdef DEBUG
            log_archdep("log_helper: internal error (invalid id or closed log), messages follows:\n", format, ap);
#endif
            return -1;
        }
    }

    if ((logi != LOG_DEFAULT) && (logi != LOG_ERR) && (*logs[logi] != '\0')) {
        logtxt = lib_msprintf("%s: %s", logs[logi], level_strings[level]);
    } else {
        logtxt = lib_msprintf("%s", level_strings[level]);
    }

    if (log_file == NULL) {
        rc = log_archdep(logtxt, format, ap);
    } else {
#ifdef ARCHDEP_EXTRA_LOG_CALL
        log_archdep(logtxt, format, ap);
#endif
        if (fputs(logtxt, log_file) == EOF
            || vfprintf(log_file, format, ap) < 0
            || fputc ('\n', log_file) == EOF) {
            rc = -1;
        }
    }

    lib_free(logtxt);

    return rc;
}
Exemplo n.º 2
0
static int log_helper(log_t log, unsigned int level, const char *format,
                      va_list ap)
{
    static const char *level_strings[3] = {
        "",
        "Warning - ",
        "Error - "
    };

    const signed int logi = (signed int)log;
    int rc = 0;
    char *logtxt = NULL;

    if (!log_enabled) {
        return 0;
    }

    if ((logi != LOG_DEFAULT) && (logi != LOG_ERR) && (logs == NULL || logs[logi] == NULL)) {
        return -1;
    }

    if ((logi != LOG_DEFAULT) && (logi != LOG_ERR) && (*logs[logi] != '\0')) {
        logtxt = lib_msprintf("%s: %s", logs[logi], level_strings[level]);
    } else {
        logtxt = lib_msprintf("%s", level_strings[level]);
    }

    if (log_file == NULL) {
        rc = log_archdep(logtxt, format, ap);
    } else {
#ifdef WIN32
        log_archdep(logtxt, format, ap);
#endif /* #ifdef WIN32 */
        if (fputs(logtxt, log_file) == EOF
            || vfprintf(log_file, format, ap) < 0
            || fputc ('\n', log_file) == EOF)
            rc = -1;
    }

    lib_free(logtxt);

    return rc;
}