diff --git a/AK/Format.cpp b/AK/Format.cpp index 27c30661b01..455ff41552f 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -26,7 +26,7 @@ #endif #if defined(AK_OS_WINDOWS) -# include +# include #endif namespace AK { @@ -1141,6 +1141,10 @@ void vout(LogLevel log_level, StringView fmtstr, TypeErasedFormatParams& params, #elif defined(AK_OS_BSD_GENERIC) || defined(AK_OS_HAIKU) auto const* progname = getprogname(); return StringView { progname, strlen(progname) }; +#elif defined AK_OS_WINDOWS + char path[MAX_PATH] = {}; + auto length = GetModuleFileName(NULL, path, MAX_PATH); + return { path, length }; #else // FIXME: Implement process_name_helper() for other platforms. return StringView {}; @@ -1157,7 +1161,7 @@ static StringView process_name_for_logging() if (!process_name_retrieved) { auto path = LexicalPath(process_name_helper()); process_name_retrieved = true; - (void)path.basename().copy_characters_to_buffer(process_name_buf, sizeof(process_name_buf)); + (void)path.title().copy_characters_to_buffer(process_name_buf, sizeof(process_name_buf)); process_name = { process_name_buf, strlen(process_name_buf) }; } return process_name; @@ -1183,6 +1187,13 @@ void set_rich_debug_enabled(bool value) is_rich_debug_enabled = value; } +#ifdef AK_OS_WINDOWS +# define YELLOW(str) "\33[93m" str "\33[0m" +static int main_thread_id = GetCurrentThreadId(); +// enable ANSI escape sequences +static int dummy = system(" "); +#endif + void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline) { if (!is_debug_enabled) @@ -1214,7 +1225,11 @@ void vdbg(StringView fmtstr, TypeErasedFormatParams& params, bool newline) #else auto process_name = process_name_for_logging(); if (!process_name.is_empty()) { - builder.appendff("{}: ", process_name); + int tid = GetCurrentThreadId(); + if (tid == main_thread_id) + builder.appendff(YELLOW("{}: "), process_name); + else + builder.appendff(YELLOW("{}:{}: "), process_name, tid); } #endif }