9#ifndef MI_BASE_ILOGGER_H
10#define MI_BASE_ILOGGER_H
62using namespace details;
73 enum {
HOST_ID_LOCAL = 0 };
76 DEVICE_ID_UNKNOWN_CUDA = -2,
77 DEVICE_ID_ALL_CUDA = -3
125 return (this->tags & required_tags) == required_tags;
194 Interface_declare<0x4afbf19a,0x5fb7,0x4422,0xae,0x4b,0x25,0x13,0x06,0x2c,0x30,0x5f>
218#ifdef MI_NEURAYLIB_DEPRECATED_LOG
232 const char* module_category,
235#ifdef MI_NEURAYLIB_DEPRECATED_LOG
266#ifdef MI_COMPILER_GCC
267 __attribute__((format(
printf, 4, 5)))
273#ifdef MI_COMPILER_MSC
274 vsnprintf_s( &buffer[0],
sizeof( buffer),
sizeof( buffer)-1,
message, args);
276 vsnprintf( buffer,
sizeof( buffer),
message, args);
288 const char* module_category,
292#ifdef MI_COMPILER_GCC
293 __attribute__((format(
printf, 5, 6)))
299#ifdef MI_COMPILER_MSC
300 vsnprintf_s( buffer,
sizeof( buffer),
sizeof( buffer)-1,
message, args);
302 vsnprintf( buffer,
sizeof( buffer),
message, args);
304 this->
message( level, module_category, details, buffer);
317class Log_streambuf :
public std::stringbuf
332 std::string module_category,
334 const Message_details& default_details = Message_details())
335 : std::stringbuf( std::ios::out),
337 m_default_level( default_level),
338 m_default_details( default_details),
339 m_module_category(std::move( module_category)),
340 m_details( default_details)
342 set_log_level( m_default_level);
346 ~Log_streambuf() noexcept override = default;
354 void set_details( const Message_details& details);
364 Log_stream& m_stream;
366 Message_details m_default_details;
367 std::
string m_module_category;
369 Message_details m_details;
402 const char* module_category,
405 : std::ostream( nullptr),
406 m_buffer( *this, module_category ? module_category :
"APP:MAIN",
407 default_level, default_details),
411#if (__cplusplus >= 201402L)
412 this->pword( get_index()) =
this;
427 const std::string& module_category,
430 : std::ostream( nullptr),
431 m_buffer( *this, module_category, default_level, default_details),
435#if (__cplusplus >= 201402L)
436 this->pword( get_index()) =
this;
455#if (__cplusplus >= 201402L)
457 static int get_index()
461 static const int s_index = std::ios_base::xalloc();
467 friend class Log_streambuf;
469 Log_streambuf m_buffer;
474 virtual void message(
476 const char* module_category,
477 const Message_details& details,
478 const char* message)
const
480 m_logger->message( level, module_category, details, message);
492inline void Log_streambuf::set_details(
const Message_details& details)
498inline int Log_streambuf::sync()
500 std::stringbuf::sync();
501 const std::string& s = str();
503 m_stream.message( m_level, m_module_category.c_str(), m_details, s.c_str());
505 m_level = m_default_level;
506 m_details = m_default_details;
521template <
typename C,
typename T>
522std::basic_ostream<C, T>&
fatal( std::basic_ostream<C, T>& ostream)
524#if (__cplusplus >= 201402L)
525 if( ostream.pword( Log_stream::get_index()) == &ostream)
540template <
typename C,
typename T>
541std::basic_ostream<C, T>&
error( std::basic_ostream<C, T>& ostream)
543#if (__cplusplus >= 201402L)
544 if( ostream.pword( Log_stream::get_index()) == &ostream)
559template <
typename C,
typename T>
560std::basic_ostream<C, T>&
warning( std::basic_ostream<C, T>& ostream)
562#if (__cplusplus >= 201402L)
563 if( ostream.pword( Log_stream::get_index()) == &ostream)
578template <
typename C,
typename T>
579std::basic_ostream<C, T>&
info( std::basic_ostream<C, T>& ostream)
581#if (__cplusplus >= 201402L)
582 if( ostream.pword( Log_stream::get_index()) == &ostream)
597template <
typename C,
typename T>
598std::basic_ostream<C, T>&
verbose( std::basic_ostream<C, T>& ostream)
600#if (__cplusplus >= 201402L)
601 if( ostream.pword( Log_stream::get_index()) == &ostream)
616template <
typename C,
typename T>
617std::basic_ostream<C, T>&
debug( std::basic_ostream<C, T>& ostream)
619#if (__cplusplus >= 201402L)
620 if( ostream.pword( Log_stream::get_index()) == &ostream)
634template <
typename C,
typename T>
635std::basic_ostream<C, T>&
operator<<( std::basic_ostream<C, T>& ostream,
const Message_details& md)
637#if (__cplusplus >= 201402L)
638 if( ostream.pword( Log_stream::get_index()) == &ostream)
640 static_cast<Log_stream&
>( ostream).set_details( md);
647using namespace details;
649using Details = Message_details;
651inline Details tag_details(
const Uint32 tags)
653 return Details().
tag(tags);
656inline Details device_details(
657 const Sint32 device=Details:
:DEVICE_ID_UNKNOWN_CUDA,
660 return Details().
tag(tags).
device(device);
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:112
The ILogger interface class supports logging of messages.
Definition: ilogger.h:195
Mixin class template for deriving new interface declarations.
Definition: interface_declare.h:43
Adapts mi::base::ILogger to a standard streaming interface.
Definition: ilogger.h:389
Configuration of the Base API.
static const Dup_interface DUP_INTERFACE
Symbolic constant to trigger a special constructor in the Handle class.
Definition: handle.h:36
bool is_device() const
Checks if this event pertains to a CUDA device or the CPU.
Definition: ilogger.h:117
std::basic_ostream<C, T> & operator<<(std::basic_ostream<C, T> &ostream, const Message_details &md)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:635
Uint32 host_id
The cluster ID of the host on which the message originated.
Definition: ilogger.h:85
Sint32 device_id
DEVICE_ID_XXX or a CUDA device ID.
Definition: ilogger.h:88
std::basic_ostream<C, T> & fatal(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:522
Message_severity
Constants for possible message severities.
Definition: enums.h:31
std::basic_ostream<C, T> & warning(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:560
Message_details & device(const Sint32 id)
Named constructor.
Definition: ilogger.h:136
Log_stream(ILogger *logger, const std::string &module_category, Message_severity default_level=MESSAGE_SEVERITY_INFO, const Message_details &default_details=Message_details())
Constructor.
Definition: ilogger.h:425
Uint32 message_id
An additional message identifier.
Definition: ilogger.h:96
std::basic_ostream<C, T> & verbose(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:598
Message_details & tag(const Uint32 t)
Named constructor.
Definition: ilogger.h:143
void printf(Message_severity level, const char *module_category, const Message_details &details, const char *message,...) __attribute__((format(printf
Emits a message to the application's log.
virtual void message(Message_severity level, const char *module_category, const Message_details &, const char *message)=0
Emits a message to the application's log.
Message_details & code(const Uint32 c)
Named constructor.
Definition: ilogger.h:158
bool is_tagged(const Uint32 required_tags) const
Checks if all required_tags are present.
Definition: ilogger.h:123
void printf(Message_severity level, const char *module_category, const char *message,...) __attribute__((format(printf
Emits a message to the application's log.
void set_log_level(Message_severity level)
Flushes the buffer if not empty, and sets the log level of the next message to the given log level.
Definition: ilogger.h:450
Uint32 tags
A set of tags.
Definition: ilogger.h:93
std::basic_ostream<C, T> & info(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:579
std::basic_ostream<C, T> & debug(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:617
std::basic_ostream<C, T> & error(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:541
Message_tag
Tags which help categorize log messages.
Definition: ilogger.h:46
~Log_stream() noexcept override
Destructor.
Definition: ilogger.h:443
Message_details & host(const Uint32 id)
Named constructor.
Definition: ilogger.h:129
Message_details & tag(const Uint32 t, const Uint32 code)
Named constructor.
Definition: ilogger.h:150
void set_details(const Message_details &details)
Flushes the buffer if not empty, and sets the message details of the next message.
Definition: ilogger.h:453
Log_stream(ILogger *logger, const char *module_category, Message_severity default_level=MESSAGE_SEVERITY_INFO, const Message_details &default_details=Message_details())
Constructor.
Definition: ilogger.h:400
virtual void message(Message_severity level, const char *module_category, const char *message)
Emits a message to the application's log.
Definition: ilogger.h:216
@ MESSAGE_SEVERITY_FATAL
A fatal error has occurred.
Definition: enums.h:33
@ MESSAGE_SEVERITY_DEBUG
This is debug message.
Definition: enums.h:43
@ MESSAGE_SEVERITY_WARNING
A warning has occurred.
Definition: enums.h:37
@ MESSAGE_SEVERITY_INFO
This is a normal operational message.
Definition: enums.h:39
@ MESSAGE_SEVERITY_VERBOSE
This is a more verbose message.
Definition: enums.h:41
@ MESSAGE_SEVERITY_ERROR
An error has occurred.
Definition: enums.h:35
@ TAG_COMPATIBILITY
hardware or library compatibility
Definition: ilogger.h:48
@ TAG_FILE
File not found, etc.
Definition: ilogger.h:55
@ TAG_STATS
e.g. timing, memory usage
Definition: ilogger.h:56
@ TAG_API_USAGE
e.g. wrong order of operations
Definition: ilogger.h:51
@ TAG_UNAVAILABLE
device or resource not available; possibly temporary
Definition: ilogger.h:57
@ TAG_UNRECOVERABLE
unrecoverable issue, e.g. fatal CUDA errors
Definition: ilogger.h:49
@ TAG_MEMORY
memory resource
Definition: ilogger.h:54
@ TAG_SYSTEM_RESOURCE
non-memory, e.g. device assignment, disk space, ...
Definition: ilogger.h:53
@ TAG_NONE
no tags
Definition: ilogger.h:47
@ TAG_API_INPUT
e.g. invalid value
Definition: ilogger.h:50
@ TAG_VERSIONING
e.g. library version info, mismatch
Definition: ilogger.h:52
int Sint32
32-bit signed integer.
Definition: types.h:46
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Smart-pointer handle class for interfaces, const and non-const version.
The basic extensible interface.
Mixin class template for deriving new interface declarations.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
Structured details to log messages.
Definition: ilogger.h:72