21 #include "date/date.h"
55 namespace onnxruntime {
59 using Timestamp = std::chrono::time_point<std::chrono::system_clock>;
65 #define ORT_USE_CXX20_STD_CHRONO __cplusplus >= 202002L
69 #include <TargetConditionals.h>
72 #if TARGET_OS_MACCATALYST
74 #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 160300)
75 #undef ORT_USE_CXX20_STD_CHRONO
81 #if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < 140400) || \
82 (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 130300)
83 #undef ORT_USE_CXX20_STD_CHRONO
89 #if ORT_USE_CXX20_STD_CHRONO
90 namespace timestamp_ns = std::chrono;
92 namespace timestamp_ns = ::date;
95 #undef ORT_USE_CXX20_STD_CHRONO
100 constexpr
bool vlog_enabled =
false;
162 const std::string* default_logger_id =
nullptr,
163 int default_max_vlog_level = -1);
170 std::unique_ptr<Logger>
CreateLogger(
const std::string& logger_id);
180 std::unique_ptr<Logger>
CreateLogger(
const std::string& logger_id,
181 Severity min_severity,
bool filter_user_data,
int max_vlog_level = -1);
238 const char* format_str, ...);
258 void CreateDefaultLogger(const std::
string& logger_id);
260 std::unique_ptr<
ISink> sink_;
265 const bool default_filter_user_data_;
266 const int default_max_vlog_level_;
267 bool owns_default_logger_;
269 static Logger* s_default_logger_;
272 const std::chrono::time_point<std::chrono::high_resolution_clock> high_res;
273 const std::chrono::time_point<std::chrono::system_clock> system;
274 const std::chrono::minutes localtime_offset_from_utc;
277 static const Epochs& GetEpochs() noexcept;
296 : logging_manager_{&loggingManager},
299 filter_user_data_{filter_user_data},
300 max_vlog_level_{vlog_level} {
321 void SetVerbosity(
int vlog_level) noexcept { max_vlog_level_ = vlog_level; }
345 logging_manager_->Log(id_, message);
353 logging_manager_->SendProfileEvent(eventRecord);
358 const std::string id_;
360 const bool filter_user_data_;
365 if (s_default_logger_ ==
nullptr) {
367 ORT_THROW(
"Attempt to use DefaultLogger but none has been registered.");
370 return *s_default_logger_;
374 if (s_default_logger_ ==
nullptr) {
376 ORT_THROW(
"Attempt to use DefaultLogger but none has been registered.");
383 if (s_default_logger_ ==
nullptr) {
385 ORT_THROW(
"Attempt to use DefaultLogger but none has been registered.");
391 inline Timestamp LoggingManager::GetTimestamp() const noexcept {
392 static const Epochs& epochs = GetEpochs();
394 const auto high_res_now = std::chrono::high_resolution_clock::now();
395 return std::chrono::time_point_cast<std::chrono::system_clock::duration>(
396 epochs.system + (high_res_now - epochs.high_res) + epochs.localtime_offset_from_utc);
Logger(const LoggingManager &loggingManager, std::string id, Severity severity, bool filter_user_data, int vlog_level)
GLuint GLsizei const GLchar * message
void Log(const std::string &logger_id, const Capture &message) const
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
std::unique_ptr< Logger > CreateLogger(const std::string &logger_id)
void SendProfileEvent(profiling::EventRecord &eventRecord) const
LoggingManager(std::unique_ptr< ISink > sink, Severity default_min_severity, bool default_filter_user_data, InstanceType instance_type, const std::string *default_logger_id=nullptr, int default_max_vlog_level=-1)
void SendProfileEvent(profiling::EventRecord &eventRecord) const
static void SetDefaultLoggerSeverity(Severity severity)
Contains potentially sensitive user data.
unsigned int GetThreadId()
Temporal instance. CreateLogger(...) should be used, however DefaultLogger() will NOT be provided via...
ORTTraceLoggingKeyword
ORT TraceLogging keywords for categories of dynamic logging enablement
unsigned int GetProcessId()
Severity OverrideLevelWithEtw(Severity originalSeverity)
static const Logger & DefaultLogger()
static const char * onnxruntime
General output.
The logging manager. Owns the log sink and potentially provides a default Logger instance. Provides filtering based on a minimum LogSeverity level, and of messages with DataType::User if enabled.
std::chrono::time_point< std::chrono::system_clock > Timestamp
void SetVerbosity(int vlog_level) noexcept
std::unique_ptr< ISink > EnhanceSinkWithEtw(std::unique_ptr< ISink > existingSink, logging::Severity originalSeverity, logging::Severity etwSeverity)
#define ORT_ATTRIBUTE_UNUSED
static void SetDefaultLoggerVerbosity(int vlog_level)
Severity GetSeverity() const noexcept
void SetSeverity(Severity severity) noexcept
bool OutputIsEnabled(Severity severity, DataType data_type) const noexcept
static LoggingManager * GetDefaultInstance()
void Log(const Capture &message) const
static bool HasDefaultLogger()
bool AddSinkOfType(SinkType sinkType, std::function< std::unique_ptr< ISink >()> sinkFactory, logging::Severity severity)
static const char * System
Log output regarding interactions with the host system.
int VLOGMaxLevel() const noexcept
void RemoveSink(SinkType sinkType)
static std::exception LogFatalAndCreateException(const char *category, const CodeLocation &location, const char *format_str,...)
Default instance of LoggingManager that should exist for the lifetime of the program.