This commit is contained in:
stasoid 2025-01-02 14:31:39 +00:00 committed by GitHub
commit 00252e42fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,7 +26,7 @@
#endif
#if defined(AK_OS_WINDOWS)
# include <io.h>
# include <AK/Windows.h>
#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
}