VART-X  0.4.0
vart::Logger Class Reference

The logger module provides the logging support for VART modules. Supports logging to console, file, syslog. More...

#include <vart_logger.hpp>

Public Member Functions

std::shared_ptr< struct log_context > mod_register (const char *modname, bool need_id)
 mod_register() - Registers a module with logger object More...
 
void vart_logger_log_obj (LogLevel, std::shared_ptr< struct log_context > ctx, const char *filename, const char *func, uint32_t line, const char *fmt,...)
 vart_logger_log_obj() - Logs a module's message along with metadata like filename, function name, line number, process id, thread id. More...
 
void set_backend (const LogBackend *backend)
 set_backend() - Install or remove a process-wide external log backend. More...
 

Static Public Member Functions

static Logger & get_instance ()
 get_instance() - Creates a logger() instance if not created earlier, else return an existing instance. More...
 

Detailed Description

The logger module provides the logging support for VART modules. Supports logging to console, file, syslog.

Member Function Documentation

◆ get_instance()

static Logger& vart::Logger::get_instance ( )
inlinestatic

get_instance() - Creates a logger() instance if not created earlier, else return an existing instance.

Returns
Returns a logger instance

On first construction Logger reads the environment variable whose name is given by the VART_CORE_DEBUG macro (the readable env-var name is "VART_CORE_DEBUG_ENV") to populate per-module and global log levels. Malformed values do not throw; the error is printed to std::cerr and defaults are kept. Default module instance id is stored as -1 and is updated when each module instance registers. Logger also reads the environment variable named by the VART_LOG_FILE_PATH macro:

  1. If set to CONSOLE, logs to the console.
  2. If set to SYSLOG, appends to syslog.
  3. If set to a file path on disk, logs to that file (falling back to syslog if the file cannot be opened).
  4. If the variable is unset, the default sink is SYSLOG.

◆ mod_register()

std::shared_ptr<struct log_context> vart::Logger::mod_register ( const char *  modname,
bool  need_id 
)

mod_register() - Registers a module with logger object

Parameters
[in]modnameModule name to register with logger
[in]need_idFlag describing the need for an id to be appended to module name during logging
Returns
Returns logger context associated with a module instance.

If the module is already registered with the logger, its instance id is incremented, else a default instance id = 0 is assigned. Module instance log level is assigned from logger object's database or from global log level if per module log level is not provided by user. If need_id is set to false, module instance id is not appended to module's instance name. Components such as 'videoframe', 'memory' need to set this flag to false as there can be too many instances of those components in a single pipeline use case and can be be distinguished by their pointers. Components representing IP blocks can set this to true to distinguish IP instances.

◆ set_backend()

void vart::Logger::set_backend ( const LogBackend *  backend)

set_backend() - Install or remove a process-wide external log backend.

Filter order: built-in env/module level -> accept (optional) -> format -> deliver when installed, otherwise the default destination.

Passing nullptr clears the current backend and restores the default destination. A non-null backend replaces the current backend. When backend is non-null, backend->deliver must be non-null. Do not call back into VART_LOG_* from accept or deliver callbacks.

◆ vart_logger_log_obj()

void vart::Logger::vart_logger_log_obj ( LogLevel  ,
std::shared_ptr< struct log_context >  ctx,
const char *  filename,
const char *  func,
uint32_t  line,
const char *  fmt,
  ... 
)

vart_logger_log_obj() - Logs a module's message along with metadata like filename, function name, line number, process id, thread id.

Parameters
[in]LogLevelLogging level with which module logs a message
[in]ctxModule's logger context obtained with mod_register()
[in]filenameSource code filename from which this logging is triggered
[in]funcSource code function name
[in]lineSource code line number
[in]fmtFormat string passed for logging, followed by a printf-style variadic argument list.

The documentation for this class was generated from the following file: