diff options
author | Andreas Kling <kling@serenityos.org> | 2020-01-21 16:14:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-21 16:16:20 +0100 |
commit | f38cfb3562cfc67ce1f878d5583c443753b9a9f2 (patch) | |
tree | 103cc43e4ea08f6d425d1d0c6b999caa387ecdf6 /AK | |
parent | 5dd5d5ca4ea265e055115ca5cbf73057574a632c (diff) | |
download | serenity-f38cfb3562cfc67ce1f878d5583c443753b9a9f2.zip |
Kernel: Tidy up debug logging a little bit
When using dbg() in the kernel, the output is automatically prefixed
with [Process(PID:TID)]. This makes it a lot easier to understand which
thread is generating the output.
This patch also cleans up some common logging messages and removes the
now-unnecessary "dbg() << *current << ..." pattern.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/LogStream.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index 2144b80842..33e58c68b8 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -24,10 +24,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <AK/String.h> #include <AK/LogStream.h> +#include <AK/String.h> #include <AK/StringView.h> +#ifdef KERNEL +# include <Kernel/Process.h> +# include <Kernel/Thread.h> +#endif + namespace AK { const LogStream& operator<<(const LogStream& stream, const String& value) @@ -62,7 +67,7 @@ const LogStream& operator<<(const LogStream& stream, const void* value) return stream << String::format("%p", value); } -#if defined (__serenity__) && !defined(KERNEL) +#if defined(__serenity__) && !defined(KERNEL) static TriState got_process_name = TriState::Unknown; static char process_name_buffer[256]; #endif @@ -70,7 +75,7 @@ static char process_name_buffer[256]; DebugLogStream dbg() { DebugLogStream stream; -#if defined (__serenity__) && !defined(KERNEL) +#if defined(__serenity__) && !defined(KERNEL) if (got_process_name == TriState::Unknown) { if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0) got_process_name = TriState::True; @@ -80,6 +85,12 @@ DebugLogStream dbg() if (got_process_name == TriState::True) stream << "\033[33;1m" << process_name_buffer << '(' << getpid() << ")\033[0m: "; #endif +#if defined(__serenity__) && defined(KERNEL) + if (current) + stream << "\033[34;1m[" << *current << "]\033[0m: "; + else + stream << "\033[36;1m[Kernel]\033[0m: "; +#endif return stream; } |