Example #1
0
void cfPS(EvalContext *ctx, LogLevel level, PromiseResult status, const Promise *pp, Attributes attr, const char *fmt, ...)
{
    /*
     * This stub implementation of cfPS delegates to the new logging backend.
     *
     * Due to the fact very little of the code has been converted, this code
     * does a full initialization and shutdown of logging subsystem for each
     * cfPS.
     *
     * Instead, LoggingInit should be called at the moment EvalContext is
     * created, LoggingPromiseEnter/LoggingPromiseFinish should be called around
     * ExpandPromise and LoggingFinish should be called when EvalContext is
     * going to be destroyed.
     *
     * But it requires all calls to cfPS to be eliminated.
     */

    /* FIXME: Ensure that NULL pp is never passed into cfPS */

    if (pp)
    {
        PromiseLoggingInit(ctx);
        PromiseLoggingPromiseEnter(ctx, pp);

        if (level == LOG_LEVEL_ERR)
        {
            LogPromiseContext(ctx, pp);
        }
    }

    va_list ap;
    va_start(ap, fmt);
    VLog(level, fmt, ap);
    va_end(ap);

    if (pp)
    {
        char *last_msg = PromiseLoggingPromiseFinish(ctx, pp);
        PromiseLoggingFinish(ctx);

        /* Now complete the exits status classes and auditing */

        ClassAuditLog(ctx, pp, attr, status);
        UpdatePromiseComplianceStatus(status, pp, last_msg);

        free(last_msg);
    }
}
Example #2
0
void cfPS(EvalContext *ctx, OutputLevel level, PromiseResult status, const char *errstr, const Promise *pp, Attributes attr, const char *fmt, ...)
{
    if ((fmt == NULL) || (strlen(fmt) == 0))
    {
        return;
    }

    va_list ap;
    va_start(ap, fmt);
    char buffer[CF_BUFSIZE];
    vsnprintf(buffer, CF_BUFSIZE - 1, fmt, ap);
    va_end(ap);

    if (Chop(buffer, CF_EXPANDSIZE) == -1)
    {
        CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator");
    }

    Item *mess = NULL;
    AppendItem(&mess, buffer, NULL);

    if ((errstr == NULL) || (strlen(errstr) > 0))
    {
        char output[CF_BUFSIZE];
        snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr());
        AppendItem(&mess, output, NULL);
    }

    if (level == OUTPUT_LEVEL_ERROR)
    {
        AmendErrorMessageWithPromiseInformation(ctx, &mess, pp);
    }

    int verbose = (attr.transaction.report_level == OUTPUT_LEVEL_VERBOSE) || VERBOSE;

    switch (level)
    {
    case OUTPUT_LEVEL_INFORM:

        if (INFORM || (attr.transaction.report_level == OUTPUT_LEVEL_INFORM)
                || VERBOSE || (attr.transaction.report_level == OUTPUT_LEVEL_VERBOSE)
                || DEBUG)
        {
            LogListStdout(mess, verbose);
        }

        if (attr.transaction.log_level == OUTPUT_LEVEL_INFORM)
        {
            SystemLog(mess, level);
        }
        break;

    case OUTPUT_LEVEL_VERBOSE:

        if (VERBOSE || (attr.transaction.log_level == OUTPUT_LEVEL_VERBOSE)
                || DEBUG)
        {
            LogListStdout(mess, verbose);
        }

        if (attr.transaction.log_level == OUTPUT_LEVEL_VERBOSE)
        {
            SystemLog(mess, level);
        }

        break;

    case OUTPUT_LEVEL_ERROR:

        LogListStdout(mess, verbose);

        if (attr.transaction.log_level == OUTPUT_LEVEL_ERROR)
        {
            SystemLog(mess, level);
        }
        break;

    case OUTPUT_LEVEL_NONE:
        break;

    default:
        ProgrammingError("Unexpected output level (%d) passed to cfPS", level);
    }

    if (pp != NULL)
    {
        LogPromiseResult(pp->promiser, pp->promisee.type, pp->promisee.item, status, attr.transaction.log_level, mess);
    }

    /* Now complete the exits status classes and auditing */

    if (pp != NULL)
    {
        ClassAuditLog(ctx, pp, attr, status);
        UpdatePromiseComplianceStatus(status, pp, buffer);
    }

    DeleteItemList(mess);
}