ONNX Runtime
Loading...
Searching...
No Matches
Ort::Logger Struct Reference

This class represents an ONNX Runtime logger that can be used to log information with an associated severity level and source code location (file path, line number, function name). More...

#include <onnxruntime_cxx_api.h>

Public Member Functions

 Logger ()=default
 
 Logger (std::nullptr_t)
 
 Logger (const OrtLogger *logger)
 
 ~Logger ()=default
 
 Logger (const Logger &)=default
 
Loggeroperator= (const Logger &)=default
 
 Logger (Logger &&v) noexcept=default
 
Loggeroperator= (Logger &&v) noexcept=default
 
OrtLoggingLevel GetLoggingSeverityLevel () const noexcept
 
Status LogMessage (OrtLoggingLevel log_severity_level, const char *file_path, int line_number, const char *func_name, const char *message) const noexcept
 
template<typename... Args>
Status LogFormattedMessage (OrtLoggingLevel log_severity_level, const char *file_path, int line_number, const char *func_name, const char *format, Args &&... args) const noexcept
 

Detailed Description

This class represents an ONNX Runtime logger that can be used to log information with an associated severity level and source code location (file path, line number, function name).

A Logger can be obtained from within custom operators by calling Ort::KernelInfo::GetLogger(). Instances of Ort::Logger are the size of two pointers and can be passed by value.

Use the ORT_CXX_LOG macros to ensure the source code location is set properly from the callsite and to take advantage of a cached logging severity level that can bypass calls to the underlying C API.

Constructor & Destructor Documentation

◆ Logger() [1/5]

Ort::Logger::Logger ( )
default

Creates an empty Ort::Logger. Must be initialized from a valid Ort::Logger before use.

◆ Logger() [2/5]

Ort::Logger::Logger ( std::nullptr_t  )
inlineexplicit

Creates an empty Ort::Logger. Must be initialized from a valid Ort::Logger before use.

◆ Logger() [3/5]

Ort::Logger::Logger ( const OrtLogger logger)
explicit

Creates a logger from an OrtLogger instance. Caches the logger's current severity level by calling OrtApi::Logger_GetLoggingSeverityLevel. Throws an exception if OrtApi::Logger_GetLoggingSeverityLevel fails.

Parameters
loggerThe OrtLogger to wrap.

◆ ~Logger()

Ort::Logger::~Logger ( )
default

◆ Logger() [4/5]

Ort::Logger::Logger ( const Logger )
default

◆ Logger() [5/5]

Ort::Logger::Logger ( Logger &&  v)
defaultnoexcept

Member Function Documentation

◆ GetLoggingSeverityLevel()

OrtLoggingLevel Ort::Logger::GetLoggingSeverityLevel ( ) const
noexcept

Returns the logger's current severity level from the cached member.

Returns
The current OrtLoggingLevel.

◆ LogFormattedMessage()

template<typename... Args>
Status Ort::Logger::LogFormattedMessage ( OrtLoggingLevel  log_severity_level,
const char *  file_path,
int  line_number,
const char *  func_name,
const char *  format,
Args &&...  args 
) const
noexcept

Logs a printf-like formatted message via OrtApi::Logger_LogMessage. Use the ORT_CXX_LOGF or ORT_CXX_LOGF_NOEXCEPT macros to properly set the source code location and to use the cached severity level to potentially bypass calls to the underlying C API. Returns an error status if a formatting error occurs.

Parameters
log_severity_levelThe message's logging severity level.
file_pathThe filepath of the file in which the message is logged. Usually the value of ORT_FILE.
line_numberThe file line number in which the message is logged. Usually the value of LINE.
func_nameThe name of the function in which the message is logged. Usually the value of FUNCTION.
formatA null-terminated UTF-8 format string forwarded to a printf-like function. Refer to https://en.cppreference.com/w/cpp/io/c/fprintf for information on valid formats.
argsZero or more variadic arguments referenced by the format string.
Returns
A Ort::Status value to indicate error or success.

◆ LogMessage()

Status Ort::Logger::LogMessage ( OrtLoggingLevel  log_severity_level,
const char *  file_path,
int  line_number,
const char *  func_name,
const char *  message 
) const
noexcept

Logs the provided message via OrtApi::Logger_LogMessage. Use the ORT_CXX_LOG or ORT_CXX_LOG_NOEXCEPT macros to properly set the source code location and to use the cached severity level to potentially bypass calls to the underlying C API.

Parameters
log_severity_levelThe message's logging severity level.
file_pathThe filepath of the file in which the message is logged. Usually the value of ORT_FILE.
line_numberThe file line number in which the message is logged. Usually the value of LINE.
func_nameThe name of the function in which the message is logged. Usually the value of FUNCTION.
messageThe message to log.
Returns
A Ort::Status value to indicate error or success.

◆ operator=() [1/2]

Logger & Ort::Logger::operator= ( const Logger )
default

◆ operator=() [2/2]

Logger & Ort::Logger::operator= ( Logger &&  v)
defaultnoexcept