diff --git a/AK/Format.cpp b/AK/Format.cpp index 60cd2dcfa6..b1eb5e6d83 100644 --- a/AK/Format.cpp +++ b/AK/Format.cpp @@ -666,8 +666,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams params) StringBuilder builder; -// FIXME: This logic is redundant with the stuff in LogStream.cpp. -#if defined(__serenity__) +#ifdef __serenity__ # ifdef KERNEL if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) { auto& thread = *Kernel::Thread::current(); @@ -695,10 +694,31 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams params) const auto string = builder.string_view(); - const auto retval = dbgputstr(string.characters_without_null_termination(), string.length()); - ASSERT(retval == 0); + dbgputstr(string.characters_without_null_termination(), string.length()); } +#ifdef KERNEL +void vdmesgln(StringView fmtstr, TypeErasedFormatParams params) +{ + StringBuilder builder; + +# ifdef __serenity__ + if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) { + auto& thread = *Kernel::Thread::current(); + builder.appendff("\033[34;1m[{}({}:{})]\033[0m: ", thread.process().name(), thread.pid().value(), thread.tid().value()); + } else { + builder.appendff("\033[34;1m[Kernel]\033[0m: "); + } +# endif + + vformat(builder, fmtstr, params); + builder.append('\n'); + + const auto string = builder.string_view(); + kernelputstr(string.characters_without_null_termination(), string.length()); +} +#endif + template struct Formatter; template struct Formatter; template struct Formatter; diff --git a/AK/Format.h b/AK/Format.h index 8b11dcb32c..ae4846eed6 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -405,6 +405,16 @@ void dbgln() { dbgln(""); } void set_debug_enabled(bool); +#ifdef KERNEL +void vdmesgln(StringView fmtstr, TypeErasedFormatParams); + +template +void dmesgln(StringView fmtstr, const Parameters&... parameters) { vdmesgln(fmtstr, VariadicFormatParams { parameters... }); } +template +void dmesgln(const char* fmtstr, const Parameters&... parameters) { vdmesgln(fmtstr, VariadicFormatParams { parameters... }); } +inline void dmesgln() { dmesgln(""); } +#endif + template struct HasFormatter : TrueType { }; @@ -459,7 +469,9 @@ struct Formatter : Formatter { } // namespace AK -#ifndef KERNEL +#ifdef KERNEL +using AK::dmesgln; +#else using AK::out; using AK::outln;