1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

AK: Add out() and warn() streams that forward to stdout and stderr

Our C++ code generator tools have been relying on host-side dbg() being
forwarded to stdout until now. Now they use out() instead.

Hopefully this will make it easier and more enticing to use streams in
userspace programs as well. :^)
This commit is contained in:
Andreas Kling 2020-04-06 10:12:10 +02:00
parent 63b11e094d
commit 0d48fb9a87
6 changed files with 219 additions and 176 deletions

View file

@ -68,6 +68,24 @@ public:
}
};
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
class StdLogStream final : public LogStream {
public:
StdLogStream(int fd)
: m_fd(fd)
{
}
virtual ~StdLogStream() override;
virtual void write(const char* characters, int length) const override;
private:
int m_fd { -1 };
};
inline StdLogStream out() { return StdLogStream(STDOUT_FILENO); }
inline StdLogStream warn() { return StdLogStream(STDERR_FILENO); }
#endif
#if !defined(BOOTSTRAPPER) && defined(KERNEL)
class KernelLogStream final : public LogStream {
public:
@ -128,3 +146,8 @@ DebugLogStream klog();
using AK::dbg;
using AK::klog;
using AK::LogStream;
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
using AK::out;
using AK::warn;
#endif