gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
gem5::Logger Class Reference

#include <logging.hh>

Classes

struct  Loc
 

Public Types

enum  LogLevel {
  PANIC , FATAL , WARN , INFO ,
  HACK , NUM_LOG_LEVELS
}
 

Public Member Functions

 Logger (const char *prefix)
 
virtual ~Logger ()
 
template<typename ... Args>
void print (const Loc &loc, const char *format, const Args &...args)
 
template<typename ... Args>
void print (const Loc &loc, const std::string &format, const Args &...args)
 
void exit_helper ()
 This helper is necessary since noreturn isn't inherited by virtual functions, and gcc will get mad if a function calls panic and then doesn't return.
 
void registerExtraLog (std::function< std::string()> cb)
 Register callback to generate extra log.
 

Static Public Member Functions

static LoggergetPanic ()
 Get a Logger for the specified type of message.
 
static LoggergetFatal ()
 
static LoggergetWarn ()
 
static LoggergetInfo ()
 
static LoggergetHack ()
 
static void setLevel (LogLevel ll)
 

Protected Member Functions

std::string getFormattedExtraLog () const
 Generate the formatted extra log string.
 
virtual void log (const Loc &loc, std::string s)
 Generates the log message.
 
virtual void exit ()
 

Protected Attributes

bool enabled
 
const char * prefix
 
std::vector< std::function< std::string()> > extraLogs
 Data structure to store extra log callbacks.
 

Detailed Description

Definition at line 57 of file logging.hh.

Member Enumeration Documentation

◆ LogLevel

Enumerator
PANIC 
FATAL 
WARN 
INFO 
HACK 
NUM_LOG_LEVELS 

Definition at line 70 of file logging.hh.

Constructor & Destructor Documentation

◆ Logger()

gem5::Logger::Logger ( const char * prefix)
inline

Definition at line 93 of file logging.hh.

References enabled, and prefix.

Referenced by TEST_F().

◆ ~Logger()

virtual gem5::Logger::~Logger ( )
inlinevirtual

Definition at line 98 of file logging.hh.

Member Function Documentation

◆ exit()

virtual void gem5::Logger::exit ( )
inlineprotectedvirtual

Definition at line 165 of file logging.hh.

Referenced by exit_helper().

◆ exit_helper()

void gem5::Logger::exit_helper ( )
inline

This helper is necessary since noreturn isn't inherited by virtual functions, and gcc will get mad if a function calls panic and then doesn't return.

Definition at line 127 of file logging.hh.

References exit().

◆ getFatal()

Logger & gem5::Logger::getFatal ( )
static

Definition at line 84 of file logging_mock.cc.

Referenced by setLevel(), TEST(), and TEST_F().

◆ getFormattedExtraLog()

std::string gem5::Logger::getFormattedExtraLog ( ) const
inlineprotected

Generate the formatted extra log string.

Developers can register extra logs when printing logs, such as PC of each CPUs, .etc. This function ensures that there's at least a new line between each extra log.

Definition at line 145 of file logging.hh.

References extraLogs, and gem5::ArmISA::ss.

Referenced by log().

◆ getHack()

Logger & gem5::Logger::getHack ( )
static

Definition at line 102 of file logging_mock.cc.

Referenced by setLevel(), TEST(), and TEST_F().

◆ getInfo()

Logger & gem5::Logger::getInfo ( )
static

Definition at line 96 of file logging_mock.cc.

Referenced by setLevel(), TEST(), and TEST_F().

◆ getPanic()

Logger & gem5::Logger::getPanic ( )
static

Get a Logger for the specified type of message.

Definition at line 78 of file logging_mock.cc.

Referenced by setLevel(), TEST(), and TEST_F().

◆ getWarn()

Logger & gem5::Logger::getWarn ( )
static

Definition at line 90 of file logging_mock.cc.

Referenced by setLevel(), TEST(), and TEST_F().

◆ log()

virtual void gem5::Logger::log ( const Loc & loc,
std::string s )
inlineprotectedvirtual

Generates the log message.

By default it is sent to cerr.

Definition at line 159 of file logging.hh.

References gem5::Logger::Loc::file, getFormattedExtraLog(), gem5::Logger::Loc::line, and gem5::ArmISA::s.

Referenced by print().

◆ print() [1/2]

template<typename ... Args>
void gem5::Logger::print ( const Loc & loc,
const char * format,
const Args &... args )
inline

◆ print() [2/2]

template<typename ... Args>
void gem5::Logger::print ( const Loc & loc,
const std::string & format,
const Args &... args )
inline

Definition at line 117 of file logging.hh.

References gem5::ArmISA::format, and print().

◆ registerExtraLog()

void gem5::Logger::registerExtraLog ( std::function< std::string()> cb)
inline

Register callback to generate extra log.

Definition at line 131 of file logging.hh.

References extraLogs.

Referenced by TEST_F().

◆ setLevel()

static void gem5::Logger::setLevel ( LogLevel ll)
inlinestatic

Member Data Documentation

◆ enabled

bool gem5::Logger::enabled
protected

Definition at line 137 of file logging.hh.

Referenced by Logger(), print(), and setLevel().

◆ extraLogs

std::vector<std::function<std::string()> > gem5::Logger::extraLogs
protected

Data structure to store extra log callbacks.

Definition at line 170 of file logging.hh.

Referenced by getFormattedExtraLog(), and registerExtraLog().

◆ prefix

const char* gem5::Logger::prefix
protected

Definition at line 167 of file logging.hh.

Referenced by Logger(), and print().


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

Generated on Mon May 26 2025 09:19:22 for gem5 by doxygen 1.13.2