9template <
typename... Args>
12 return std::vformat(fmt_str, std::make_format_args(args...));
37 static void shutdown();
51 std::string_view message,
52 std::source_location location = std::source_location::current());
64 std::string_view message,
65 std::source_location location = std::source_location::current());
77 std::string_view message);
83 void add_sink(std::unique_ptr<Sink> sink);
104 void set_min_severity(
Severity min_sev);
111 void set_component_filter(
Component comp,
bool enabled);
117 void set_component_includes(
const std::vector<Component>& components);
124 void set_context_filter(
Context ctx,
bool enabled);
130 void set_context_includes(
const std::vector<Context>& contexts);
157 std::source_location location, std::string_view message)
170template <
typename... Args>
172 std::source_location location,
const char* msg_or_fmt, Args&&... args)
174 if constexpr (
sizeof...(Args) == 0) {
176 std::string_view(msg_or_fmt), location);
178 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
195 std::source_location location, std::string_view message)
208template <
typename... Args>
210 std::source_location location,
211 const char* msg_or_fmt, Args&&... args)
213 if constexpr (
sizeof...(Args) == 0) {
215 std::string_view(msg_or_fmt), location);
217 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
233 std::string_view message)
246template <
typename... Args>
248 const char* msg_or_fmt, Args&&... args)
250 if constexpr (
sizeof...(Args) == 0) {
252 std::string_view(msg_or_fmt));
254 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
270 std::cout <<
"[MayaFlux] " << message <<
'\n';
281template <
typename... Args>
282inline void format_print(std::format_string<std::remove_cvref_t<Args>...> fmt_str, Args&&... args)
284 std::cout <<
"[MayaFlux] " <<
format(fmt_str, std::forward<Args>(args)...) <<
'\n';
295template <
typename... Args>
298 std::cout <<
"[MayaFlux] " <<
format_runtime(fmt_str, std::forward<Args>(args)...) <<
'\n';
310 std::source_location location, std::string_view message)
326template <
typename... Args>
328 std::source_location location, std::format_string<Args...> fmt_str, Args&&... args)
330 auto msg =
format(fmt_str, std::forward<Args>(args)...);
344template <
typename ExceptionType = std::runtime_error>
346 std::source_location location,
347 std::string_view message)
351 throw ExceptionType(std::string(message));
364template <
typename ExceptionType = std::runtime_error,
typename... Args>
366 std::source_location location,
const char* fmt_str, Args&&... args)
368 if constexpr (
sizeof...(Args) == 0) {
370 std::string_view(fmt_str), location);
372 throw ExceptionType(std::string(fmt_str));
377 throw ExceptionType(msg);
390 std::source_location location = std::source_location::current(),
391 std::string_view additional_context =
"")
393 auto ep = std::current_exception();
396 "error_rethrow called outside of a catch", location);
402 std::rethrow_exception(ep);
403 }
catch (
const std::exception& e) {
404 std::string msg = std::string(e.what());
405 if (!additional_context.empty()) {
406 msg = std::string(additional_context) +
": " + msg;
410 std::rethrow_exception(ep);
412 std::string msg =
"Unknown exception";
413 if (!additional_context.empty()) {
414 msg = std::string(additional_context) +
": " + msg;
418 std::rethrow_exception(ep);
431template <
typename... Args>
433 std::source_location location,
const char* fmt_str, Args&&... args)
436 error_rethrow(component, context, location, std::string_view(msg));
445#define MF_TRACE(comp, ctx, ...) \
446 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
447 std::source_location::current(), __VA_ARGS__)
449#define MF_DEBUG(comp, ctx, ...) \
450 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
451 std::source_location::current(), __VA_ARGS__)
453#define MF_INFO(comp, ctx, ...) \
454 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::INFO, comp, ctx, \
455 std::source_location::current(), __VA_ARGS__)
457#define MF_WARN(comp, ctx, ...) \
458 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::WARN, comp, ctx, \
459 std::source_location::current(), __VA_ARGS__)
461#define MF_ERROR(comp, ctx, ...) \
462 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
463 std::source_location::current(), __VA_ARGS__)
465#define MF_ASSERT(comp, ctx, condition, ...) \
467 if (!(condition)) [[unlikely]] { \
468 MayaFlux::Journal::scribe( \
469 MayaFlux::Journal::Severity::ERROR, comp, ctx, \
470 std::source_location::current(), \
471 "Assertion failed: " #condition ". " __VA_ARGS__); \
472 MayaFlux::Journal::Archivist::instance().shutdown(); \
481#define MF_RT_TRACE(comp, ctx, ...) \
482 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
483 std::source_location::current(), __VA_ARGS__)
485#define MF_RT_WARN(comp, ctx, ...) \
486 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::WARN, comp, ctx, \
487 std::source_location::current(), __VA_ARGS__)
489#define MF_RT_ERROR(comp, ctx, ...) \
490 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
491 std::source_location::current(), __VA_ARGS__)
493#define MF_RT_DEBUG(comp, ctx, ...) \
494 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
495 std::source_location::current(), __VA_ARGS__)
500#define MF_LOG(comp, ctx, ...) MayaFlux::Journal::log(comp, ctx, __VA_ARGS__)
505#define MF_PRINT(...) MayaFlux::Journal::format_print(__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.
void flush()
Synchronously drain all pending ring buffer entries to sinks.
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.
void format_print(std::string_view message)
Print formatted output directly to stdout with MayaFlux prefix.
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 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.
void log(Component component, Context context, std::string_view message)
Log a simple message without source-location.
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.