mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 17:24:48 -05:00
AK: Add outf, warnf and dbgf.
This commit is contained in:
parent
b7a4c4482f
commit
5ed15a49f2
Notes:
sideshowbarker
2024-07-19 02:15:44 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/5ed15a49f23 Pull-request: https://github.com/SerenityOS/serenity/pull/3587
3 changed files with 33 additions and 0 deletions
|
@ -142,6 +142,12 @@ void vformat(StringBuilder& builder, StringView fmtstr, AK::Span<const TypeErase
|
|||
|
||||
vformat(builder, fmtstr.substring_view(closing + 1), parameters, argument_index);
|
||||
}
|
||||
void vformat(const LogStream& stream, StringView fmtstr, Span<const TypeErasedParameter> parameters)
|
||||
{
|
||||
StringBuilder builder;
|
||||
vformat(builder, fmtstr, parameters);
|
||||
stream << builder.to_string();
|
||||
}
|
||||
|
||||
bool Formatter<StringView>::parse(StringView flags)
|
||||
{
|
||||
|
|
|
@ -92,5 +92,6 @@ Array<TypeErasedParameter, sizeof...(Parameters)> make_type_erased_parameters(co
|
|||
}
|
||||
|
||||
void vformat(StringBuilder& builder, StringView fmtstr, Span<const TypeErasedParameter>, size_t argument_index = 0);
|
||||
void vformat(const LogStream& stream, StringView fmtstr, Span<const TypeErasedParameter>);
|
||||
|
||||
} // namespace AK
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/kmalloc.h>
|
||||
|
@ -206,13 +207,38 @@ DebugLogStream klog();
|
|||
|
||||
void dump_bytes(ReadonlyBytes);
|
||||
|
||||
#ifndef KERNEL
|
||||
template<typename... Parameters>
|
||||
void outf(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
const auto type_erased_parameters = make_type_erased_parameters(parameters...);
|
||||
vformat(out(), fmtstr, type_erased_parameters);
|
||||
}
|
||||
template<typename... Parameters>
|
||||
void warnf(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
const auto type_erased_parameters = make_type_erased_parameters(parameters...);
|
||||
vformat(warn(), fmtstr, type_erased_parameters);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename... Parameters>
|
||||
void dbgf(StringView fmtstr, const Parameters&... parameters)
|
||||
{
|
||||
const auto type_erased_parameters = make_type_erased_parameters(parameters...);
|
||||
vformat(dbg(), fmtstr, type_erased_parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::dbg;
|
||||
using AK::dbgf;
|
||||
using AK::klog;
|
||||
using AK::LogStream;
|
||||
|
||||
#if !defined(KERNEL)
|
||||
using AK::out;
|
||||
using AK::outf;
|
||||
using AK::warn;
|
||||
using AK::warnf;
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue