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);
102 void set_context_filter(
Context ctx,
bool enabled);
129 std::source_location location, std::string_view message)
142template <
typename... Args>
144 std::source_location location,
const char* msg_or_fmt, Args&&... args)
146 if constexpr (
sizeof...(Args) == 0) {
148 std::string_view(msg_or_fmt), location);
150 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
167 std::source_location location, std::string_view message)
180template <
typename... Args>
182 std::source_location location,
183 const char* msg_or_fmt, Args&&... args)
185 if constexpr (
sizeof...(Args) == 0) {
187 std::string_view(msg_or_fmt), location);
189 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
205 std::string_view message)
218template <
typename... Args>
220 const char* msg_or_fmt, Args&&... args)
222 if constexpr (
sizeof...(Args) == 0) {
224 std::string_view(msg_or_fmt));
226 auto msg =
format_runtime(msg_or_fmt, std::forward<Args>(args)...);
242 std::cout <<
"[MayaFlux] " << message <<
'\n';
253template <
typename... Args>
256 std::cout <<
"[MayaFlux] " <<
format(fmt_str, std::forward<Args>(args)...) <<
'\n';
267template <
typename... Args>
270 std::cout <<
"[MayaFlux] " <<
format_runtime(fmt_str, std::forward<Args>(args)...) <<
'\n';
282 std::source_location location, std::string_view message)
297template <
typename... Args>
301 auto msg =
format(fmt_str, std::forward<Args>(args)...);
314template <
typename ExceptionType = std::runtime_error>
316 std::source_location location,
317 std::string_view message)
321 throw ExceptionType(std::string(message));
334template <
typename ExceptionType = std::runtime_error,
typename... Args>
336 std::source_location location,
const char* fmt_str, Args&&... args)
338 if constexpr (
sizeof...(Args) == 0) {
340 std::string_view(fmt_str), location);
341 throw ExceptionType(std::string(fmt_str));
345 throw ExceptionType(msg);
358 std::source_location location = std::source_location::current(),
359 std::string_view additional_context =
"")
361 auto ep = std::current_exception();
364 "error_rethrow called outside of a catch", location);
369 std::rethrow_exception(ep);
370 }
catch (
const std::exception& e) {
371 std::string msg = std::string(e.what());
372 if (!additional_context.empty()) {
373 msg = std::string(additional_context) +
": " + msg;
376 std::rethrow_exception(ep);
378 std::string msg =
"Unknown exception";
379 if (!additional_context.empty()) {
380 msg = std::string(additional_context) +
": " + msg;
383 std::rethrow_exception(ep);
396template <
typename... Args>
398 std::source_location location,
const char* fmt_str, Args&&... args)
400 if constexpr (
sizeof...(Args) == 0) {
402 std::string_view(fmt_str));
404 auto additional_context =
format_runtime(fmt_str, std::forward<Args>(args)...);
405 error_rethrow(component, context, location, additional_context);
414#define MF_TRACE(comp, ctx, ...) \
415 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
416 std::source_location::current(), __VA_ARGS__)
418#define MF_DEBUG(comp, ctx, ...) \
419 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
420 std::source_location::current(), __VA_ARGS__)
422#define MF_INFO(comp, ctx, ...) \
423 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::INFO, comp, ctx, \
424 std::source_location::current(), __VA_ARGS__)
426#define MF_WARN(comp, ctx, ...) \
427 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::WARN, comp, ctx, \
428 std::source_location::current(), __VA_ARGS__)
430#define MF_ERROR(comp, ctx, ...) \
431 MayaFlux::Journal::scribe(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
432 std::source_location::current(), __VA_ARGS__)
434#define MF_ASSERT(comp, ctx, condition, ...) \
436 if (!(condition)) [[unlikely]] { \
437 MayaFlux::Journal::scribe( \
438 MayaFlux::Journal::Severity::ERROR, comp, ctx, \
439 std::source_location::current(), \
440 "Assertion failed: " #condition ". " __VA_ARGS__); \
441 MayaFlux::Journal::Archivist::instance().shutdown(); \
450#define MF_RT_TRACE(comp, ctx, ...) \
451 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::TRACE, comp, ctx, \
452 std::source_location::current(), __VA_ARGS__)
454#define MF_RT_WARN(comp, ctx, ...) \
455 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::WARN, comp, ctx, \
456 std::source_location::current(), __VA_ARGS__)
458#define MF_RT_ERROR(comp, ctx, ...) \
459 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::ERROR, comp, ctx, \
460 std::source_location::current(), __VA_ARGS__)
462#define MF_RT_DEBUG(comp, ctx, ...) \
463 MayaFlux::Journal::scribe_rt(MayaFlux::Journal::Severity::DEBUG, comp, ctx, \
464 std::source_location::current(), __VA_ARGS__)
469#define MF_LOG(comp, ctx, ...) MayaFlux::Journal::log(comp, ctx, __VA_ARGS__)
474#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.
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.
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 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 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.