AK: Add support for Kernel Log Stream

This commit is contained in:
Liav A 2020-02-28 17:10:30 +02:00 committed by Andreas Kling
parent dc01a71fac
commit 9440c45d6e
Notes: sideshowbarker 2024-07-19 08:56:02 +09:00
2 changed files with 45 additions and 0 deletions

View file

@ -126,6 +126,31 @@ DebugLogStream dbg()
return stream;
}
#if defined(KERNEL)
KernelLogStream klog()
{
KernelLogStream stream;
if (Kernel::Thread::current)
stream << "\033[34;1m[" << *Kernel::Thread::current << "]\033[0m: ";
else
stream << "\033[36;1m[Kernel]\033[0m: ";
return stream;
}
#elif !defined(BOOTSTRAPPER)
DebugLogStream klog()
{
return dbg();
}
#endif
#if defined(KERNEL)
KernelLogStream::~KernelLogStream()
{
char newline = '\n';
write(&newline, 1);
}
#endif
DebugLogStream::~DebugLogStream()
{
char newline = '\n';

View file

@ -70,6 +70,19 @@ public:
}
};
#if !defined(BOOTSTRAPPER) && defined(KERNEL)
class KernelLogStream final : public LogStream {
public:
KernelLogStream() {}
virtual ~KernelLogStream() override;
virtual void write(const char* characters, int length) const override
{
kernelputstr(characters, length);
}
};
#endif
inline const LogStream& operator<<(const LogStream& stream, const char* value)
{
int length = 0;
@ -103,7 +116,14 @@ inline const LogStream& operator<<(const LogStream& stream, bool value)
DebugLogStream dbg();
#if defined(KERNEL)
KernelLogStream klog();
#elif !defined(BOOTSTRAPPER)
DebugLogStream klog();
#endif
}
using AK::dbg;
using AK::klog;
using AK::LogStream;