summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-08-15 20:55:45 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-08-15 20:55:45 +0200
commit5122caf9a8c05147e488db1fb249968f2029de61 (patch)
tree753987cec1fa97193499087772faccf535515baa /AK
parent6ad3efe0671cb428a10b6825daa8f03f56ff9cc2 (diff)
downloadserenity-5122caf9a8c05147e488db1fb249968f2029de61.zip
LogStream: Prefix userspace dbg() output with "ProcessName(PID): "
Using the new get_process_name() syscall, we can automatically prefix all userspace debug logging. Hopefully this is more helpful than annoying. We'll find out! :^)
Diffstat (limited to 'AK')
-rw-r--r--AK/LogStream.cpp21
-rw-r--r--AK/LogStream.h16
2 files changed, 28 insertions, 9 deletions
diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp
index 4d64179843..d0d29de11e 100644
--- a/AK/LogStream.cpp
+++ b/AK/LogStream.cpp
@@ -49,4 +49,25 @@ const LogStream& operator<<(const LogStream& stream, const TStyle& style)
return stream;
}
+#ifdef USERLAND
+static TriState got_process_name = TriState::Unknown;
+static char process_name_buffer[256];
+#endif
+
+DebugLogStream dbg()
+{
+ DebugLogStream stream;
+#ifdef USERLAND
+ if (got_process_name == TriState::Unknown) {
+ if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0)
+ got_process_name = TriState::True;
+ else
+ got_process_name = TriState::False;
+ }
+ if (got_process_name == TriState::True)
+ stream << TStyle(TStyle::Color::Brown, TStyle::Attribute::Bold) << process_name_buffer << '(' << getpid() << ")" << TStyle(TStyle::None) << ": ";
+#endif
+ return stream;
+}
+
}
diff --git a/AK/LogStream.h b/AK/LogStream.h
index 81480adfb6..ff685caa5c 100644
--- a/AK/LogStream.h
+++ b/AK/LogStream.h
@@ -3,8 +3,10 @@
#include <AK/kstdio.h>
#ifdef USERLAND
-#include <AK/ScopedValueRollback.h>
-#include <errno.h>
+# include <AK/ScopedValueRollback.h>
+# include <AK/StringView.h>
+# include <errno.h>
+# include <unistd.h>
#endif
namespace AK {
@@ -14,8 +16,7 @@ class StringView;
class TStyle {
public:
- enum NoneTag { DummyValue };
- static NoneTag None;
+ enum NoneTag { None };
enum Color {
Black = 0,
@@ -98,11 +99,6 @@ public:
}
};
-inline DebugLogStream dbg()
-{
- return {};
-}
-
inline const LogStream& operator<<(const LogStream& stream, const char* value)
{
int length = 0;
@@ -131,6 +127,8 @@ inline const LogStream& operator<<(const LogStream& stream, bool value)
return stream << (value ? "true" : "false");
}
+DebugLogStream dbg();
+
}
using AK::dbg;