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"); } }
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); } } }
void LogToStdout(const char *msg, LogLevel level, bool color) { if (LEGACY_OUTPUT) { if (level >= LOG_LEVEL_VERBOSE) { printf("%s> %s\n", VPREFIX, msg); } else { printf("%s\n", msg); } } else { struct tm now; time_t now_seconds = time(NULL); localtime_r(&now_seconds, &now); char formatted_timestamp[25]; if (strftime(formatted_timestamp, 25, "%Y-%m-%dT%H:%M:%S%z", &now) == 0) { // There was some massacre formating the timestamp. Wow strlcpy(formatted_timestamp, "<unknown>", sizeof(formatted_timestamp)); } const char *string_level = LogLevelToString(level); if (color) { printf("%s%-24s %8s: %s\x1b[0m\n", LogLevelToColor(level), formatted_timestamp, string_level, msg); } else { printf("%-24s %8s: %s\n", formatted_timestamp, string_level, msg); } } }