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 to a file-based 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

// Set global level to Err
LIEF::logging::set_level(LIEF::logging::Level::Err);

{
  // 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
Err = 5
Info = 3
Off = 0
Trace = 1
Warn = 4

Example

# Set global level to Err
lief.logging.set_level(lief.logging.Level.Err)

# 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")

Rust

Example

// Set global level to Err
lief::logging::set_level(lief::logging::Level::Err);

{
    // Temporarily set global level to Debug (RAII)
    let _scoped = lief::logging::Scoped::new(lief::logging::Level::Debug);
    lief::logging::log(lief::logging::Level::Debug, "This is a debug message");
}