Logging

This section details the API for interacting with LIEF’s logging engine.

LIEF uses spdlog for its logging mechanism, and this API provides an abstraction over that implementation.

API

C++

void LIEF::logging::disable()

Globally disable the logging module.

void LIEF::logging::enable()

Globally enable the logging module.

void LIEF::logging::set_level(LEVEL level)

Change the logging level (hierarchical).

void LIEF::logging::set_path(const std::string &path)

Change the logger as a file-base logging and set its path.

template<typename ...Args>
void LIEF::logging::log(LEVEL level, const std::string &fmt, const Args&... args)
void LIEF::logging::log(LEVEL level, const std::string &fmt, const std::vector<std::string> &args)
void LIEF::logging::log(LEVEL level, const std::string &msg)

Log a message with the LIEF’s logger.

void LIEF::logging::reset()
enum class LIEF::logging::LEVEL : uint32_t

Hierarchical logging level

From a given level set, all levels below this ! level are enabled

For example, if LEVEL::INFO is enabled then LEVEL::WARN, LEVEL::ERR are also enabled

Values:

enumerator OFF = 0
enumerator TRACE
enumerator DEBUG
enumerator INFO
enumerator WARN
enumerator ERR
enumerator CRITICAL
class Scoped

Public Functions

Scoped(const Scoped&) = delete
Scoped &operator=(const Scoped&) = delete
Scoped(Scoped&&) = delete
Scoped &operator=(Scoped&&) = delete
inline explicit Scoped(LEVEL level)
inline explicit Scoped(LEVEL level, std::string name)
inline const Scoped &set_level(LEVEL lvl) const
inline void reset()
inline ~Scoped()

Example

#include <LIEF/logging.hpp>

// Set global level to ERROR
LIEF::logging::set_level(LIEF::logging::LEVEL::ERROR);

{
  // Temporarily set global level to DEBUG (RAII)
  LIEF::logging::Scoped _(LIEF::logging::LEVEL::DEBUG);
  LIEF::logging::log(LIEF::logging::LEVEL::DEBUG, "This is a debug message");
}

Python

lief.logging.set_level(level: lief.logging.LEVEL) None

Change logging level

lief.logging.enable() None

Enable the logger globally

lief.logging.disable() None

Disable the logger globally

lief.logging.set_path(path: str | os.PathLike) None

Change the logger as a file-base logging and set its path

lief.logging.log(level: lief.logging.LEVEL, msg: str) None

Log a message with the LIEF’s logger

lief.logging.level_scope(name: str, lvl: LEVEL) Scoped
lief.logging.level_scope(name: str, lvl: LEVEL) Scoped
class lief.logging.Scoped

Bases: object

class lief.logging.LEVEL(*values)

Bases: Enum

CRITICAL = 6
DEBUG = 2
ERROR = 5
INFO = 3
OFF = 0
TRACE = 1
WARN = 4

Example

import lief

# Set global level to ERROR
lief.logging.set_level(lief.logging.LEVEL.ERROR)

# Temporarily set global level to DEBUG
with lief.logging.level_scope(lief.logging.LEVEL.DEBUG):
    lief.logging.log(lief.logging.LEVEL.DEBUG, "This is a debug message")