Beispiel #1
0
/*
 * Add an output channel to <logger> that writes to the file specified with
 * <fmt> and the subsequent parameters. If the file could not be opened, -1 is
 * returned and the channel is not created.
 */
int logToFile(Logger *logger, const char *fmt, ...)
{
    va_list ap;

    FILE *fp;
    Buffer filename = { 0 };

    va_start(ap, fmt);
    bufSetV(&filename, fmt, ap);
    va_end(ap);

    if ((fp = fopen(bufGet(&filename), "w")) == NULL) {
        bufReset(&filename);

        return -1;
    }
    else {
        pthread_mutex_lock(&logger->access);

        LOG_Output *out = log_create_output(logger, LOG_OT_FILE);
        out->u.fp = fp;

        pthread_mutex_unlock(&logger->access);

        bufReset(&filename);

        return 0;
    }
}
Beispiel #2
0
/*
 * Set <buf> to a string formatted according to <fmt> and the subsequent parameters.
 */
Buffer *bufSetF(Buffer *buf, const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);

    bufSetV(buf, fmt, ap);

    va_end(ap);

    return buf;
}
Beispiel #3
0
/*
 * Add a string defined by <fmt> and the subsequent arguments to log messages.
 */
void logWithString(Logger *logger, const char *fmt, ...)
{
    va_list ap;
    Buffer string = { 0 };

    pthread_mutex_lock(&logger->access);

    LOG_Prefix *prefix = log_add_prefix(logger, LOG_PT_STR);

    va_start(ap, fmt);
    bufSetV(&string, fmt, ap);
    va_end(ap);

    prefix->u.string = bufDetach(&string);

    pthread_mutex_unlock(&logger->access);
}