summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-09-23 14:45:41 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-23 21:45:28 +0200
commit5ed15a49f2320274fc9ed7c639abdc9d3e407fb4 (patch)
tree5d2d4c3debb0ec2e23df31747e3bb0c760f55122 /AK
parentb7a4c4482fdb839ba767d5125aed6e35e34276d1 (diff)
downloadserenity-5ed15a49f2320274fc9ed7c639abdc9d3e407fb4.zip
AK: Add outf, warnf and dbgf.
Diffstat (limited to 'AK')
-rw-r--r--AK/Format.cpp6
-rw-r--r--AK/Format.h1
-rw-r--r--AK/LogStream.h26
3 files changed, 33 insertions, 0 deletions
diff --git a/AK/Format.cpp b/AK/Format.cpp
index 9868a559b2..18a3819c25 100644
--- a/AK/Format.cpp
+++ b/AK/Format.cpp
@@ -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)
{
diff --git a/AK/Format.h b/AK/Format.h
index 0d9ba16349..8646915da0 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -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
diff --git a/AK/LogStream.h b/AK/LogStream.h
index cfe88f1d14..5cbafccadf 100644
--- a/AK/LogStream.h
+++ b/AK/LogStream.h
@@ -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