mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:08:12 +00:00
AK+Format: Add dmesgln() to replace klog().
This commit is contained in:
parent
1c1e577a5e
commit
a7d5fbb8af
2 changed files with 37 additions and 5 deletions
|
@ -666,8 +666,7 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams params)
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
// FIXME: This logic is redundant with the stuff in LogStream.cpp.
|
#ifdef __serenity__
|
||||||
#if defined(__serenity__)
|
|
||||||
# ifdef KERNEL
|
# ifdef KERNEL
|
||||||
if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) {
|
if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) {
|
||||||
auto& thread = *Kernel::Thread::current();
|
auto& thread = *Kernel::Thread::current();
|
||||||
|
@ -695,10 +694,31 @@ void vdbgln(StringView fmtstr, TypeErasedFormatParams params)
|
||||||
|
|
||||||
const auto string = builder.string_view();
|
const auto string = builder.string_view();
|
||||||
|
|
||||||
const auto retval = dbgputstr(string.characters_without_null_termination(), string.length());
|
dbgputstr(string.characters_without_null_termination(), string.length());
|
||||||
ASSERT(retval == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
void vdmesgln(StringView fmtstr, TypeErasedFormatParams params)
|
||||||
|
{
|
||||||
|
StringBuilder builder;
|
||||||
|
|
||||||
|
# ifdef __serenity__
|
||||||
|
if (Kernel::Processor::is_initialized() && Kernel::Thread::current()) {
|
||||||
|
auto& thread = *Kernel::Thread::current();
|
||||||
|
builder.appendff("\033[34;1m[{}({}:{})]\033[0m: ", thread.process().name(), thread.pid().value(), thread.tid().value());
|
||||||
|
} else {
|
||||||
|
builder.appendff("\033[34;1m[Kernel]\033[0m: ");
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
vformat(builder, fmtstr, params);
|
||||||
|
builder.append('\n');
|
||||||
|
|
||||||
|
const auto string = builder.string_view();
|
||||||
|
kernelputstr(string.characters_without_null_termination(), string.length());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
template struct Formatter<unsigned char, void>;
|
template struct Formatter<unsigned char, void>;
|
||||||
template struct Formatter<unsigned short, void>;
|
template struct Formatter<unsigned short, void>;
|
||||||
template struct Formatter<unsigned int, void>;
|
template struct Formatter<unsigned int, void>;
|
||||||
|
|
14
AK/Format.h
14
AK/Format.h
|
@ -405,6 +405,16 @@ void dbgln() { dbgln<enabled>(""); }
|
||||||
|
|
||||||
void set_debug_enabled(bool);
|
void set_debug_enabled(bool);
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
void vdmesgln(StringView fmtstr, TypeErasedFormatParams);
|
||||||
|
|
||||||
|
template<typename... Parameters>
|
||||||
|
void dmesgln(StringView fmtstr, const Parameters&... parameters) { vdmesgln(fmtstr, VariadicFormatParams { parameters... }); }
|
||||||
|
template<typename... Parameters>
|
||||||
|
void dmesgln(const char* fmtstr, const Parameters&... parameters) { vdmesgln(fmtstr, VariadicFormatParams { parameters... }); }
|
||||||
|
inline void dmesgln() { dmesgln(""); }
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename T, typename = void>
|
template<typename T, typename = void>
|
||||||
struct HasFormatter : TrueType {
|
struct HasFormatter : TrueType {
|
||||||
};
|
};
|
||||||
|
@ -459,7 +469,9 @@ struct Formatter<FormatString> : Formatter<String> {
|
||||||
|
|
||||||
} // namespace AK
|
} // namespace AK
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifdef KERNEL
|
||||||
|
using AK::dmesgln;
|
||||||
|
#else
|
||||||
using AK::out;
|
using AK::out;
|
||||||
using AK::outln;
|
using AK::outln;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue