1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

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.
This commit is contained in:
Andreas Kling 2020-01-21 16:14:39 +01:00
parent 5dd5d5ca4e
commit f38cfb3562
9 changed files with 41 additions and 38 deletions

View file

@ -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;
@ -79,6 +84,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;
}