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);
118 void set_context_filter(
Context ctx,
bool enabled);
145 std::source_location location, std::string_view message)
158template <
typename... Args>
160 std::source_location location,
const char* msg_or_fmt, Args&&... args)
162 if constexpr (
sizeof...(Args) == 0) {
164 std::string_view(msg_or_fmt), location);
166 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
183 std::source_location location, std::string_view message)
196template <
typename... Args>
198 std::source_location location,
199 const char* msg_or_fmt, Args&&... args)
201 if constexpr (
sizeof...(Args) == 0) {
203 std::string_view(msg_or_fmt), location);
205 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
221 std::string_view message)
234template <
typename... Args>
236 const char* msg_or_fmt, Args&&... args)
238 if constexpr (
sizeof...(Args) == 0) {
240 std::string_view(msg_or_fmt));
242 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
258 std::cout <<
"[MayaFlux] " << message <<
'\n';
269template <
typename... Args>
270inline void format_print(std::format_string<std::remove_cvref_t<Args>...> fmt_str, Args&&... args)
272 std::cout <<
"[MayaFlux] " << format(fmt_str, std::forward<Args>(args)...) <<
'\n';
283template <
typename... Args>
286 std::cout <<
"[MayaFlux] " <<
format_runtime(fmt_str, std::forward<Args>(args)...) <<
'\n';
298 std::source_location location, std::string_view message)
314template <
typename... Args>
316 std::source_location location, std::format_string<Args...> fmt_str, Args&&... args)
318 auto msg = format(fmt_str, std::forward<Args>(args)...);
332template <
typename ExceptionType = std::runtime_error>
334 std::source_location location,
335 std::string_view message)
339 throw ExceptionType(std::string(message));
352template <
typename ExceptionType = std::runtime_error,
typename... Args>
354 std::source_location location,
const char* fmt_str, Args&&... args)
356 if constexpr (
sizeof...(Args) == 0) {
358 std::string_view(fmt_str), location);
360 throw ExceptionType(std::string(fmt_str));
365 throw ExceptionType(msg);
378 std::source_location location = std::source_location::current(),
379 std::string_view additional_context =
"")
381 auto ep = std::current_exception();
384 "error_rethrow called outside of a catch", location);
390 std::rethrow_exception(ep);
391 }
catch (
const std::exception& e) {
392 std::string msg = std::string(e.what());
393 if (!additional_context.empty()) {
394 msg = std::string(additional_context) +
": " + msg;
398 std::rethrow_exception(ep);
400 std::string msg =
"Unknown exception";
401 if (!additional_context.empty()) {
402 msg = std::string(additional_context) +
": " + msg;
406 std::rethrow_exception(ep);
419template <
typename... Args>
421 std::source_location location,
const char* fmt_str, Args&&... args)
424 error_rethrow(component, context, location, std::string_view(msg));
433#define MF_TRACE(comp, ctx, ...) \
434 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
435 std::source_location::current(), __VA_ARGS__)
437#define MF_DEBUG(comp, ctx, ...) \
438 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
439 std::source_location::current(), __VA_ARGS__)
441#define MF_INFO(comp, ctx, ...) \
442 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::INFO, comp, ctx, \
443 std::source_location::current(), __VA_ARGS__)
445#define MF_WARN(comp, ctx, ...) \
446 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::WARN, comp, ctx, \
447 std::source_location::current(), __VA_ARGS__)
449#define MF_ERROR(comp, ctx, ...) \
450 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
451 std::source_location::current(), __VA_ARGS__)
453#define MF_ASSERT(comp, ctx, condition, ...) \
455 if (!(condition)) [[unlikely]] { \
456 MayaFlux::Journal::scribe( \
457 MayaFlux::Journal::Severity::ERROR, comp, ctx, \
458 std::source_location::current(), \
459 "Assertion failed: " #condition ". " __VA_ARGS__); \
460 MayaFlux::Journal::Archivist::instance().shutdown(); \
469#define MF_RT_TRACE(comp, ctx, ...) \
470 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
471 std::source_location::current(), __VA_ARGS__)
473#define MF_RT_WARN(comp, ctx, ...) \
474 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::WARN, comp, ctx, \
475 std::source_location::current(), __VA_ARGS__)
477#define MF_RT_ERROR(comp, ctx, ...) \
478 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
479 std::source_location::current(), __VA_ARGS__)
481#define MF_RT_DEBUG(comp, ctx, ...) \
482 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
483 std::source_location::current(), __VA_ARGS__)
488#define MF_LOG(comp, ctx, ...) MayaFlux::Journal::log(comp, ctx, __VA_ARGS__)
493#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.