Beispiel #1
0
static void LogToConsole(const char *msg, LogLevel level, bool color)
{
    FILE *output_file = stdout; // Messages should ALL go to stdout else they are disordered
    struct tm now;
    time_t now_seconds = time(NULL);
    localtime_r(&now_seconds, &now);

    if (color)
    {
        fprintf(output_file, "%s", LogLevelToColor(level));
    }
    if (level >= LOG_LEVEL_INFO && VPREFIX[0])
    {
        fprintf(stdout, "%s ", VPREFIX);
    }
    if (TIMESTAMPS)
    {
        char formatted_timestamp[64];
        LoggingFormatTimestamp(formatted_timestamp, 64, &now);
        fprintf(stdout, "%s ", formatted_timestamp);
    }

    fprintf(stdout, "%8s: %s\n", LogLevelToString(level), msg);

    if (color)
    {
        // Turn off the color again.
        fprintf(output_file, "\x1b[0m");
    }
}
Beispiel #2
0
static void LogToConsole(const char *msg, LogLevel level, bool color)
{
    FILE *output_file = stdout; // Messages should ALL go to stdout else they are disordered
    struct tm now;
    time_t now_seconds = time(NULL);
    localtime_r(&now_seconds, &now);

    char formatted_timestamp[64];
    LoggingFormatTimestamp(formatted_timestamp, 64, &now);

    if (MACHINE_OUTPUT)
    {
        const char *string_level = LogLevelToString(level);

        if (color)
        {
            fprintf(output_file, "%s%s %8s: %s\x1b[0m\n", LogLevelToColor(level),
                    formatted_timestamp, string_level, msg);
        }
        else
        {
            fprintf(output_file, "%s %8s: %s\n", formatted_timestamp, string_level, msg);
        }
    }
    else
    {
        if (level >= LOG_LEVEL_INFO && VPREFIX[0])
        {
            fprintf(stdout, "%s ", VPREFIX);
        }

        if (!BePretty)
        {
            fprintf(stdout, "%s ", formatted_timestamp);
        }

        if (level <= LOG_LEVEL_INFO)
        {
            fprintf(stdout, "%s %s\n", LogLevelToString(level), msg);
        }
        else
        {
            fprintf(stdout, "%s\n", msg);
        }
    }
}