9#ifndef MI_BASE_ILOGGER_H
10#define MI_BASE_ILOGGER_H
61using namespace details;
72 enum {
HOST_ID_LOCAL = 0 };
75 DEVICE_ID_UNKNOWN_CUDA = -2,
76 DEVICE_ID_ALL_CUDA = -3
124 return (this->tags & required_tags) == required_tags;
193 Interface_declare<0x4afbf19a,0x5fb7,0x4422,0xae,0x4b,0x25,0x13,0x06,0x2c,0x30,0x5f>
217#ifdef MI_NEURAYLIB_DEPRECATED_LOG
231 const char* module_category,
234#ifdef MI_NEURAYLIB_DEPRECATED_LOG
265#ifdef MI_COMPILER_GCC
266 __attribute__((format(
printf, 4, 5)))
272#ifdef MI_COMPILER_MSC
273 vsnprintf_s( &buffer[0],
sizeof( buffer),
sizeof( buffer)-1,
message, args);
275 vsnprintf( buffer,
sizeof( buffer),
message, args);
287 const char* module_category,
291#ifdef MI_COMPILER_GCC
292 __attribute__((format(
printf, 5, 6)))
298#ifdef MI_COMPILER_MSC
299 vsnprintf_s( buffer,
sizeof( buffer),
sizeof( buffer)-1,
message, args);
301 vsnprintf( buffer,
sizeof( buffer),
message, args);
303 this->
message( level, module_category, details, buffer);
316class Log_streambuf :
public std::stringbuf
331 const std::string& module_category,
333 const Message_details& default_details = Message_details())
334 : std::stringbuf( std::ios::out),
336 m_default_level( default_level),
337 m_default_details( default_details),
338 m_module_category( module_category),
339 m_details( default_details)
341 set_log_level( m_default_level);
345 ~Log_streambuf() throw()
355 void set_details(
const Message_details& details);
365 Log_stream& m_stream;
367 Message_details m_default_details;
368 std::string m_module_category;
370 Message_details m_details;
403 const char* module_category,
407 m_buffer( *this, module_category ? module_category :
"APP:MAIN",
408 default_level, default_details),
412#if (__cplusplus >= 201402L)
413 this->pword( get_index()) =
this;
428 const std::string& module_category,
432 m_buffer( *this, module_category, default_level, default_details),
436#if (__cplusplus >= 201402L)
437 this->pword( get_index()) =
this;
456#if (__cplusplus >= 201402L)
458 static int get_index()
462 static const int s_index = std::ios_base::xalloc();
468 friend class Log_streambuf;
470 Log_streambuf m_buffer;
475 virtual void message(
477 const char* module_category,
478 const Message_details& details,
479 const char* message)
const
481 m_logger->message( level, module_category, details, message);
493inline void Log_streambuf::set_details(
const Message_details& details)
499inline int Log_streambuf::sync()
501 std::stringbuf::sync();
502 const std::string& s = str();
504 m_stream.message( m_level, m_module_category.c_str(), m_details, s.c_str());
506 m_level = m_default_level;
507 m_details = m_default_details;
522template <
typename C,
typename T>
523std::basic_ostream<C, T>&
fatal( std::basic_ostream<C, T>& ostream)
525#if (__cplusplus >= 201402L)
526 if( ostream.pword( Log_stream::get_index()) == &ostream)
541template <
typename C,
typename T>
542std::basic_ostream<C, T>&
error( std::basic_ostream<C, T>& ostream)
544#if (__cplusplus >= 201402L)
545 if( ostream.pword( Log_stream::get_index()) == &ostream)
560template <
typename C,
typename T>
561std::basic_ostream<C, T>&
warning( std::basic_ostream<C, T>& ostream)
563#if (__cplusplus >= 201402L)
564 if( ostream.pword( Log_stream::get_index()) == &ostream)
579template <
typename C,
typename T>
580std::basic_ostream<C, T>&
info( std::basic_ostream<C, T>& ostream)
582#if (__cplusplus >= 201402L)
583 if( ostream.pword( Log_stream::get_index()) == &ostream)
598template <
typename C,
typename T>
599std::basic_ostream<C, T>&
verbose( std::basic_ostream<C, T>& ostream)
601#if (__cplusplus >= 201402L)
602 if( ostream.pword( Log_stream::get_index()) == &ostream)
617template <
typename C,
typename T>
618std::basic_ostream<C, T>&
debug( std::basic_ostream<C, T>& ostream)
620#if (__cplusplus >= 201402L)
621 if( ostream.pword( Log_stream::get_index()) == &ostream)
635template <
typename C,
typename T>
636std::basic_ostream<C, T>&
operator<<( std::basic_ostream<C, T>& ostream,
const Message_details& md)
638#if (__cplusplus >= 201402L)
639 if( ostream.pword( Log_stream::get_index()) == &ostream)
641 static_cast<Log_stream&
>( ostream).set_details( md);
648using namespace details;
650typedef Message_details Details;
652inline Details tag_details(
const Uint32 tags)
654 return Details().
tag(tags);
657inline Details device_details(
658 const Sint32 device=Details:
:DEVICE_ID_UNKNOWN_CUDA,
661 return Details().
tag(tags).
device(device);
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
The ILogger interface class supports logging of messages.
Definition: ilogger.h:194
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:390
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:37
bool is_device() const
Checks if this event pertains to a CUDA device or the CPU.
Definition: ilogger.h:116
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:636
Uint32 host_id
The cluster ID of the host on which the message originated.
Definition: ilogger.h:84
Sint32 device_id
DEVICE_ID_XXX or a CUDA device ID.
Definition: ilogger.h:87
std::basic_ostream<C, T> & fatal(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:523
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:561
Message_details & device(const Sint32 id)
Named constructor.
Definition: ilogger.h:135
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:426
Uint32 message_id
An additional message identifier.
Definition: ilogger.h:95
std::basic_ostream<C, T> & verbose(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:599
Message_details & tag(const Uint32 t)
Named constructor.
Definition: ilogger.h:142
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:157
bool is_tagged(const Uint32 required_tags) const
Checks if all required_tags are present.
Definition: ilogger.h:122
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:451
Uint32 tags
A set of tags.
Definition: ilogger.h:92
std::basic_ostream<C, T> & info(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:580
std::basic_ostream<C, T> & debug(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:618
std::basic_ostream<C, T> & error(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:542
Message_tag
Tags which help categorize log messages.
Definition: ilogger.h:45
Message_details & host(const Uint32 id)
Named constructor.
Definition: ilogger.h:128
Message_details & tag(const Uint32 t, const Uint32 code)
Named constructor.
Definition: ilogger.h:149
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:454
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:401
virtual void message(Message_severity level, const char *module_category, const char *message)
Emits a message to the application's log.
Definition: ilogger.h:215
~Log_stream()
Destructor.
Definition: ilogger.h:444
@ 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:47
@ TAG_FILE
File not found, etc.
Definition: ilogger.h:54
@ TAG_STATS
e.g. timing, memory usage
Definition: ilogger.h:55
@ TAG_API_USAGE
e.g. wrong order of operations
Definition: ilogger.h:50
@ TAG_UNAVAILABLE
device or resource not available; possibly temporary
Definition: ilogger.h:56
@ TAG_UNRECOVERABLE
unrecoverable issue, e.g. fatal CUDA errors
Definition: ilogger.h:48
@ TAG_MEMORY
memory resource
Definition: ilogger.h:53
@ TAG_SYSTEM_RESOURCE
non-memory, e.g. device assignment, disk space, ...
Definition: ilogger.h:52
@ TAG_NONE
no tags
Definition: ilogger.h:46
@ TAG_API_INPUT
e.g. invalid value
Definition: ilogger.h:49
@ TAG_VERSIONING
e.g. library version info, mismatch
Definition: ilogger.h:51
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
signed int Sint32
32-bit signed integer.
Definition: types.h:46
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: dice.h:89
Structured details to log messages.
Definition: ilogger.h:71