USRP Hardware Driver and USRP Manual: log.hpp File Reference

| USRP Hardware Driver and USRP Manual Version: 4.9.0.makepkg-0-g9ec1f582 UHD and USRP Manual |

Loading...
Searching...
No Matches
log.hpp File Reference
`#include <uhd/config.hpp>`
`#include <boost/date_time/posix_time/posix_time_types.hpp>`
`#include <boost/optional.hpp>`
`#include <iomanip>`
`#include <iostream>`
`#include <ostream>`
`#include <sstream>`
`#include <string>`
`#include <thread>`

Go to the source code of this file.

## Classes
struct | uhd::log::logging_info

## Namespaces
namespace | uhd
namespace | uhd::log

## Macros
#define | UHD_LOG_TRACE(component, message)
#define | UHD_LOG_DEBUG(component, message)
#define | UHD_LOG_INFO(component, message)
#define | UHD_LOG_WARNING(component, message)
#define | UHD_LOG_ERROR(component, message)
#define | UHD_LOG_THROW(exception_type, component, message)
#define | UHD_LOG_FATAL(component, message)
#define | RFNOC_LOG_TRACE(message)
#define | RFNOC_LOG_DEBUG(message)
#define | RFNOC_LOG_INFO(message)
#define | RFNOC_LOG_WARNING(message)
#define | RFNOC_LOG_ERROR(message)
#define | RFNOC_LOG_FATAL(message)
#define | UHD_LOG_FASTPATH(message)
| Extra-fast logging macro for when speed matters.
#define | UHD_LOGGER_TRACE(component)
#define | UHD_LOGGER_DEBUG(component)
#define | UHD_LOGGER_INFO(component)
#define | UHD_LOGGER_WARNING(component)
#define | UHD_LOGGER_ERROR(component)
#define | UHD_LOGGER_FATAL(component)
#define | UHD_HERE()
| Helpful debug tool to print site info.
#define | UHD_VAR(var)
| Helpful debug tool to print a variable.
#define | UHD_HEX(var)
| Helpful debug tool to print a variable in hex.

## Enumerations
enum | uhd::log::severity_level { uhd::log::trace = 0 , uhd::log::debug = 1 , uhd::log::info = 2 , uhd::log::warning = 3 , uhd::log::error = 4 , uhd::log::fatal = 5 , uhd::log::off = 6 }

## Functions
boost::optional< uhd::log::severity_level > UHD_API | uhd::log::parse_log_level_from_string (const std::string &log_level_str)
UHD_API void | uhd::log::set_log_level (uhd::log::severity_level level)
UHD_API void | uhd::log::set_console_level (uhd::log::severity_level level)
UHD_API void | uhd::log::set_file_level (uhd::log::severity_level level)
UHD_API void | uhd::log::set_logger_level (const std::string &logger, uhd::log::severity_level level)

## Detailed Description

# The UHD logging facility

The logger enables UHD library code to easily log events into a file and display messages above a certain level in the terminal. Log entries are time-stamped and stored with file, line, and function. Each call to the UHD_LOG macros is thread-safe. Each thread will aquire the lock for the logger.

Note: More information on the logging subsystem can be found on UHD Logging.

To disable console logging completely at compile time specify -DUHD_LOG_CONSOLE_DISABLE during configuration with CMake.

By default no file logging will occur. Set a log file path:

- at compile time by specifying -DUHD_LOG_FILE=$file_path
- and/or override at runtime by setting the environment variable UHD_LOG_FILE

## Log levels

See also Log levels.

All log messages with verbosity greater than or equal to the log level (in other words, as often or less often than the current log level) are recorded to std::clog and/or the log file. Log levels can be specified using string or numeric values of uhd::log::severity_level.

The minimum log level is defined by -DUHD_LOG_MIN_LEVEL at compile time, and this value can be increased at runtime by specifying the UHD_LOG_LEVEL environment variable. This minimum logging level applies to any form of runtime logging. Thus for example if this minimum is set to 3 (info), then during runtime no logging at levels below 3 can be provided.

The following set the minimum logging level to 3 (info):

- Example pre-processor define: -DUHD_LOG_MIN_LEVEL=3
- Example pre-processor define: -DUHD_LOG_MIN_LEVEL=info
- Example environment variable: export UHD_LOG_LEVEL=3
- Example environment variable: export UHD_LOG_LEVEL=info

The actual log level for console and file logging can be configured by setting UHD_LOG_CONSOLE_LEVEL or UHD_LOG_FILE_LEVEL, respectively. The default values for these variables can be defined using the cmake flags -DUHD_LOG_CONSOLE_LEVEL and -DUHD_LOG_FILE_LEVEL, respectively.

These variables can be the name of a verbosity enum or integer value:

- Example pre-processor define: -DUHD_LOG_CONSOLE_LEVEL=3
- Example pre-processor define: -DUHD_LOG_CONSOLE_LEVEL=info
- Example environment variable: export UHD_LOG_CONSOLE_LEVEL=3
- Example environment variable: export UHD_LOG_CONSOLE_LEVEL=info

The UHD_LOG_FILE_LEVEL variable can be used in the same way.

## Log formatting

The log format for messages going into a log file is CSV. All log messages going into a logfile will contain following fields:

- timestamp
- thread-id
- source-file + line information
- severity level
- component/channel information which logged the information
- the actual log message

The log format of log messages displayed on the terminal is plain text with space separated tags prepended. For example:

- [INFO] [X300] This is a informational log message

The log format for log output on the console by using these preprocessor defines in CMake:

- -DUHD_LOG_CONSOLE_TIME adds a timestamp [2017-01-01 00:00:00.000000]
- -DUHD_LOG_CONSOLE_THREAD adds a thread-id [0x001234]
- -DUHD_LOG_CONSOLE_SRC adds a sourcefile and line tag [src_file:line]

## Macro Definition Documentation

## ◆ RFNOC_LOG_DEBUG

#define RFNOC_LOG_DEBUG | ( |  | message | ) |

Value:
UHD_LOG_DEBUG(this->get_unique_id(), message)
UHD_LOG_DEBUG
#define UHD_LOG_DEBUG(component,...)
Definition log.h:46

## ◆ RFNOC_LOG_ERROR

#define RFNOC_LOG_ERROR | ( |  | message | ) |

Value:
UHD_LOG_ERROR(this->get_unique_id(), message)
UHD_LOG_ERROR
#define UHD_LOG_ERROR(component,...)
Definition log.h:67

## ◆ RFNOC_LOG_FATAL

#define RFNOC_LOG_FATAL | ( |  | message | ) |

Value:
UHD_LOG_FATAL(this->get_unique_id(), message)
UHD_LOG_FATAL
#define UHD_LOG_FATAL(component,...)
Definition log.h:74

## ◆ RFNOC_LOG_INFO

#define RFNOC_LOG_INFO | ( |  | message | ) |

Value:
UHD_LOG_INFO(this->get_unique_id(), message)
UHD_LOG_INFO
#define UHD_LOG_INFO(component,...)
Definition log.h:53

## ◆ RFNOC_LOG_TRACE

#define RFNOC_LOG_TRACE | ( |  | message | ) |

Value:
UHD_LOG_TRACE(this->get_unique_id(), message)
UHD_LOG_TRACE
#define UHD_LOG_TRACE(component,...)
Definition log.h:39

## ◆ RFNOC_LOG_WARNING

#define RFNOC_LOG_WARNING | ( |  | message | ) |

Value:
UHD_LOG_WARNING(this->get_unique_id(), message)
UHD_LOG_WARNING
#define UHD_LOG_WARNING(component,...)
Definition log.h:60

## ◆ UHD_HERE

#define UHD_HERE | ( |  | ) |

Value:
UHD_LOGGER_DEBUG("DEBUG") << __FILE__ << ":" << __LINE__;
UHD_LOGGER_DEBUG
#define UHD_LOGGER_DEBUG(component)
Definition log.hpp:270

Helpful debug tool to print site info.

## ◆ UHD_HEX

#define UHD_HEX | ( |  | var | ) |

Value:
UHD_LOGGER_DEBUG("DEBUG") << #var << " = 0x" << std::hex << std::setfill('0') \
<< std::setw(8) << var << std::dec;

Helpful debug tool to print a variable in hex.

## ◆ UHD_LOG_DEBUG

#define UHD_LOG_DEBUG | ( |  | component,
|  |  | message )

Value:
_UHD_LOG_INTERNAL(component, uhd::log::debug) << message;
uhd::log::debug
@ debug
Definition log.hpp:118

## ◆ UHD_LOG_ERROR

#define UHD_LOG_ERROR | ( |  | component,
|  |  | message )

Value:
_UHD_LOG_INTERNAL(component, uhd::log::error) << message;
uhd::log::error
@ error
Definition log.hpp:121

## ◆ UHD_LOG_FASTPATH

#define UHD_LOG_FASTPATH | ( |  | message | ) |

Value:
uhd::_log::log_fastpath(message);

Extra-fast logging macro for when speed matters.

## ◆ UHD_LOG_FATAL

#define UHD_LOG_FATAL | ( |  | component,
|  |  | message )

Value:
_UHD_LOG_INTERNAL(component, uhd::log::fatal) << message;
uhd::log::fatal
@ fatal
Definition log.hpp:122

## ◆ UHD_LOG_INFO

#define UHD_LOG_INFO | ( |  | component,
|  |  | message )

Value:
_UHD_LOG_INTERNAL(component, uhd::log::info) << message;
uhd::log::info
@ info
Definition log.hpp:119

## ◆ UHD_LOG_THROW

#define UHD_LOG_THROW | ( |  | exception_type,
|  |  | component,
|  |  | message )

Value:
{ \
std::ostringstream __ss; \
__ss << message; \
UHD_LOG_ERROR(component, __ss.str()); \
throw exception_type(__ss.str()); \
}

## ◆ UHD_LOG_TRACE

#define UHD_LOG_TRACE | ( |  | component,
|  |  | message )

Value:
_UHD_LOG_INTERNAL(component, uhd::log::trace) << message;
uhd::log::trace
@ trace
Definition log.hpp:117

## ◆ UHD_LOG_WARNING

#define UHD_LOG_WARNING | ( |  | component,
|  |  | message )

Value:
_UHD_LOG_INTERNAL(component, uhd::log::warning) << message;
uhd::log::warning
@ warning
Definition log.hpp:120

## ◆ UHD_LOGGER_DEBUG

#define UHD_LOGGER_DEBUG | ( |  | component | ) |

Value:
_UHD_LOG_INTERNAL(component, uhd::log::debug)

## ◆ UHD_LOGGER_ERROR

#define UHD_LOGGER_ERROR | ( |  | component | ) |

Value:
_UHD_LOG_INTERNAL(component, uhd::log::error)

## ◆ UHD_LOGGER_FATAL

#define UHD_LOGGER_FATAL | ( |  | component | ) |

Value:
_UHD_LOG_INTERNAL(component, uhd::log::fatal)

## ◆ UHD_LOGGER_INFO

#define UHD_LOGGER_INFO | ( |  | component | ) |

Value:
_UHD_LOG_INTERNAL(component, uhd::log::info)

## ◆ UHD_LOGGER_TRACE

#define UHD_LOGGER_TRACE | ( |  | component | ) |

Value:
_UHD_LOG_INTERNAL(component, uhd::log::trace)

## ◆ UHD_LOGGER_WARNING

#define UHD_LOGGER_WARNING | ( |  | component | ) |

Value:
_UHD_LOG_INTERNAL(component, uhd::log::warning)

## ◆ UHD_VAR

#define UHD_VAR | ( |  | var | ) |

Value:
UHD_LOGGER_DEBUG("DEBUG") << #var << " = " << var;

Helpful debug tool to print a variable.