30 static void shutdown();
44 std::string_view message,
45 std::source_location location = std::source_location::current());
57 std::string_view message,
58 std::source_location location = std::source_location::current());
70 std::string_view message);
76 void add_sink(std::unique_ptr<Sink> sink);
88 void set_min_severity(
Severity min_sev);
95 void set_component_filter(
Component comp,
bool enabled);
122 std::source_location location, std::string_view message)
135template <
typename... Args>
137 std::source_location location,
const char* msg_or_fmt, Args&&... args)
139 if constexpr (
sizeof...(Args) == 0) {
141 std::string_view(msg_or_fmt), location);
143 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
160 std::source_location location, std::string_view message)
173template <
typename... Args>
175 std::source_location location,
176 const char* msg_or_fmt, Args&&... args)
178 if constexpr (
sizeof...(Args) == 0) {
180 std::string_view(msg_or_fmt), location);
182 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
198 std::string_view message)
211template <
typename... Args>
213 const char* msg_or_fmt, Args&&... args)
215 if constexpr (
sizeof...(Args) == 0) {
217 std::string_view(msg_or_fmt));
219 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
233 std::source_location location, std::string_view message)
248template <
typename... Args>
252 auto msg =
format(fmt_str, std::forward<Args>(args)...);
265template <
typename ExceptionType = std::runtime_error>
267 std::source_location location,
268 std::string_view message)
272 throw ExceptionType(std::string(message));
285template <
typename ExceptionType = std::runtime_error,
typename... Args>
287 std::source_location location,
const char* fmt_str, Args&&... args)
289 if constexpr (
sizeof...(Args) == 0) {
291 std::string_view(fmt_str), location);
292 throw ExceptionType(std::string(fmt_str));
296 throw ExceptionType(msg);
309 std::source_location location = std::source_location::current(),
310 std::string_view additional_context =
"")
312 auto ep = std::current_exception();
315 "error_rethrow called outside of a catch", location);
320 std::rethrow_exception(ep);
321 }
catch (
const std::exception& e) {
322 std::string msg = std::string(e.what());
323 if (!additional_context.empty()) {
324 msg = std::string(additional_context) +
": " + msg;
327 std::rethrow_exception(ep);
329 std::string msg =
"Unknown exception";
330 if (!additional_context.empty()) {
331 msg = std::string(additional_context) +
": " + msg;
334 std::rethrow_exception(ep);
347template <
typename... Args>
349 std::source_location location,
const char* fmt_str, Args&&... args)
351 if constexpr (
sizeof...(Args) == 0) {
353 std::string_view(fmt_str));
356 auto additional_context =
format_runtime(fmt_str, std::forward<Args>(args)...);
357 error_rethrow(component, context, location, additional_context);
366#define MF_TRACE(comp, ctx, ...) \
367 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
368 std::source_location::current(), __VA_ARGS__)
370#define MF_DEBUG(comp, ctx, ...) \
371 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
372 std::source_location::current(), __VA_ARGS__)
374#define MF_INFO(comp, ctx, ...) \
375 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::INFO, comp, ctx, \
376 std::source_location::current(), __VA_ARGS__)
378#define MF_WARN(comp, ctx, ...) \
379 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::WARN, comp, ctx, \
380 std::source_location::current(), __VA_ARGS__)
382#define MF_ERROR(comp, ctx, ...) \
383 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
384 std::source_location::current(), __VA_ARGS__)
390#define MF_RT_TRACE(comp, ctx, ...) \
391 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
392 std::source_location::current(), __VA_ARGS__)
394#define MF_RT_WARN(comp, ctx, ...) \
395 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::WARN, comp, ctx, \
396 std::source_location::current(), __VA_ARGS__)
398#define MF_RT_ERROR(comp, ctx, ...) \
399 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
400 std::source_location::current(), __VA_ARGS__)
402#define MF_RT_DEBUG(comp, ctx, ...) \
403 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
404 std::source_location::current(), __VA_ARGS__)
409#define MF_PRINT(comp, ctx, ...) MayaFlux::Journal::print(comp, ctx, __VA_ARGS__)
void scribe_simple(Component component, Context context, std::string_view message)
Log a simple message without source location information.
void scribe_rt(Severity severity, Component component, Context context, std::string_view message, std::source_location location=std::source_location::current())
Log a message from a real-time context with the specified severity, component, and context.
Archivist(const Archivist &)=delete
static Archivist & instance()
Get the singleton instance of the Archivist.
Archivist & operator=(Archivist &&)=delete
Archivist & operator=(const Archivist &)=delete
void scribe(Severity severity, Component component, Context context, std::string_view message, std::source_location location=std::source_location::current())
Log a message with the specified severity, component, and context.
Archivist(Archivist &&)=delete
std::unique_ptr< Impl > m_impl
Singleton class responsible for managing log entries.
Context
Execution contexts for log messages.
void error_rethrow(Component component, Context context, std::source_location location=std::source_location::current(), std::string_view additional_context="")
Catch and log an exception, then rethrow it.
void error(Component component, Context context, std::source_location location, std::string_view message)
Log an error message and optionally throw an exception.
fmt::format_string< Args... > format_string
void fatal(Component component, Context context, std::source_location location, std::string_view message)
Log a fatal message and abort the program.
std::string format_runtime(std::string_view fmt_str, Args &&... args)
void print(Component component, Context context, std::string_view message)
Log a simple message without source-location.
void scribe(Severity severity, Component component, Context context, std::source_location location, std::string_view message)
Log a message with the specified severity, component, and context.
std::string format(format_string< std::remove_cvref_t< Args >... > fmt_str, Args &&... args)
void scribe_rt(Severity severity, Component component, Context context, std::source_location location, std::string_view message)
Log a message in a real-time context with automatic source location.