diff options
author | Liav A <liavalb@gmail.com> | 2020-02-28 17:10:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-02 22:23:39 +0100 |
commit | 9440c45d6e167544ff5b4199f77c5872424b45a6 (patch) | |
tree | d9d0d6a4385f7ca08d58bcd1e551de9b13986fb5 /AK | |
parent | dc01a71fac2cb6b596b864d9c135a163b3df7847 (diff) | |
download | serenity-9440c45d6e167544ff5b4199f77c5872424b45a6.zip |
AK: Add support for Kernel Log Stream
Diffstat (limited to 'AK')
-rw-r--r-- | AK/LogStream.cpp | 25 | ||||
-rw-r--r-- | AK/LogStream.h | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index 245a52558d..31eca75b88 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -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'; diff --git a/AK/LogStream.h b/AK/LogStream.h index 8e00ad278d..e0fa4e9ce3 100644 --- a/AK/LogStream.h +++ b/AK/LogStream.h @@ -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; |