Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
ErrorLogging.hpp
Go to the documentation of this file.
1#pragma once
2
10
11#include <icarus/core/Error.hpp>
13
14namespace icarus {
15
20 switch (severity) {
21 case Severity::INFO:
22 return LogLevel::Info;
24 return LogLevel::Warning;
25 case Severity::ERROR:
26 return LogLevel::Error;
27 case Severity::FATAL:
28 return LogLevel::Fatal;
29 }
30 return LogLevel::Error;
31}
32
36inline void LogError(const Error &error, double time = 0.0, const std::string &component = "") {
37 auto sim_error = error.toSimulationError(time, component);
38 LogLevel level = SeverityToLogLevel(sim_error.severity);
39
40 // Use component as context if provided
41 if (!component.empty()) {
42 LogContext ctx;
43 ctx.component = component;
44 GetLogService().Log(level, time, sim_error.message, ctx);
45 } else {
46 GetLogService().Log(level, time, sim_error.message);
47 }
48}
49
58template <typename E>
59[[noreturn]] void ThrowAndLog(E &&error, double time = 0.0, const std::string &component = "") {
60 LogError(error, time, component);
61 throw std::forward<E>(error);
62}
63
64} // namespace icarus
65
66// =============================================================================
67// Logging-Enabled Throw Macros
68// =============================================================================
69
70// NOLINTBEGIN(cppcoreguidelines-macro-usage)
71
76#define ICARUS_THROW_LOG(error) ::icarus::ThrowAndLog((error), 0.0, "")
77
84#define ICARUS_THROW_LOG_CTX(error, time, component) \
85 ::icarus::ThrowAndLog((error), (time), (component))
86
87// NOLINTEND(cppcoreguidelines-macro-usage)
Consolidated error handling for Icarus.
Unified logging service for Icarus.
Base class for all Icarus exceptions.
Definition Error.hpp:52
SimulationError toSimulationError(double time=0.0, const std::string &component="") const
Convert to SimulationError for ErrorHandler integration.
Definition Error.hpp:63
void Log(LogLevel level, double sim_time, std::string_view message)
Log a message (uses current thread-local context).
Definition LogService.hpp:352
Definition AggregationTypes.hpp:13
void ThrowAndLog(E &&error, double time=0.0, const std::string &component="")
Throw an error after logging it.
Definition ErrorLogging.hpp:59
Severity
Definition Error.hpp:22
@ WARNING
Warning (may trigger graceful degradation).
Definition Error.hpp:24
@ FATAL
Fatal (simulation must stop).
Definition Error.hpp:26
@ INFO
Informational (logged, no action).
Definition Error.hpp:23
@ ERROR
Error (simulation may continue with fallback).
Definition Error.hpp:25
LogLevel SeverityToLogLevel(Severity severity)
Convert error severity to log level.
Definition ErrorLogging.hpp:19
void LogError(const Error &error, double time=0.0, const std::string &component="")
Log an error to the global LogService.
Definition ErrorLogging.hpp:36
LogLevel
Log severity levels.
Definition Console.hpp:35
@ Warning
Potential issues.
Definition Console.hpp:40
@ Info
Normal operation.
Definition Console.hpp:38
@ Fatal
Unrecoverable errors.
Definition Console.hpp:42
@ Error
Recoverable errors.
Definition Console.hpp:41
LogService & GetLogService()
Global log service singleton.
Definition LogService.hpp:536
Immutable log context - set by component/entity during execution.
Definition LogService.hpp:98
std::string component
Component name (e.g., "merlinEngine2").
Definition LogService.hpp:100