mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
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! :^)
This commit is contained in:
parent
6ad3efe067
commit
5122caf9a8
2 changed files with 28 additions and 9 deletions
|
@ -49,4 +49,25 @@ const LogStream& operator<<(const LogStream& stream, const TStyle& style)
|
||||||
return stream;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
|
|
||||||
#ifdef USERLAND
|
#ifdef USERLAND
|
||||||
#include <AK/ScopedValueRollback.h>
|
# include <AK/ScopedValueRollback.h>
|
||||||
#include <errno.h>
|
# include <AK/StringView.h>
|
||||||
|
# include <errno.h>
|
||||||
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -14,8 +16,7 @@ class StringView;
|
||||||
|
|
||||||
class TStyle {
|
class TStyle {
|
||||||
public:
|
public:
|
||||||
enum NoneTag { DummyValue };
|
enum NoneTag { None };
|
||||||
static NoneTag None;
|
|
||||||
|
|
||||||
enum Color {
|
enum Color {
|
||||||
Black = 0,
|
Black = 0,
|
||||||
|
@ -98,11 +99,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline DebugLogStream dbg()
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const LogStream& operator<<(const LogStream& stream, const char* value)
|
inline const LogStream& operator<<(const LogStream& stream, const char* value)
|
||||||
{
|
{
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
@ -131,6 +127,8 @@ inline const LogStream& operator<<(const LogStream& stream, bool value)
|
||||||
return stream << (value ? "true" : "false");
|
return stream << (value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DebugLogStream dbg();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::dbg;
|
using AK::dbg;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue