summaryrefslogtreecommitdiff
path: root/AK/LogStream.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-06 10:12:10 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-06 10:49:27 +0200
commit0d48fb9a8770adc089f5e5943b4c359115909524 (patch)
treee3f70330a438d3f930c86c9d25ddd08a30d3963e /AK/LogStream.cpp
parent63b11e094db38fc433e6a105c3f559b0c69bef7d (diff)
downloadserenity-0d48fb9a8770adc089f5e5943b4c359115909524.zip
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. :^)
Diffstat (limited to 'AK/LogStream.cpp')
-rw-r--r--AK/LogStream.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp
index e2a49cc076..dac64adfe1 100644
--- a/AK/LogStream.cpp
+++ b/AK/LogStream.cpp
@@ -34,6 +34,10 @@
# include <Kernel/Thread.h>
#endif
+#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
+#include <stdio.h>
+#endif
+
namespace AK {
const LogStream& operator<<(const LogStream& stream, const String& value)
@@ -163,4 +167,20 @@ DebugLogStream::~DebugLogStream()
write(&newline, 1);
}
+#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
+StdLogStream::~StdLogStream()
+{
+ char newline = '\n';
+ write(&newline, 1);
+}
+
+void StdLogStream::write(const char* characters, int length) const
+{
+ if (::write(m_fd, characters, length) < 0) {
+ perror("StdLogStream::write");
+ ASSERT_NOT_REACHED();
+ }
+}
+#endif
+
}