The Sparta Modeling Framework
Loading...
Searching...
No Matches
Logger Output Macros

Macros

#define SPARTA_LOG_CODE_BLOCK(logger, code)
 
#define DLOG_CODE_BLOCK(code)   SPARTA_LOG_CODE_BLOCK(debug_logger_, code)
 
#define ILOG_CODE_BLOCK(code)   SPARTA_LOG_CODE_BLOCK( info_logger_, code)
 
#define WLOG_CODE_BLOCK(code)   SPARTA_LOG_CODE_BLOCK( warn_logger_, code)
 
#define SPARTA_LOG_OUTPUT(logger, msg)   logger << __func__ << ": " << msg;
 
#define DLOG_OUTPUT(msg)   SPARTA_LOG_OUTPUT(debug_logger_, msg)
 
#define ILOG_OUTPUT(msg)   SPARTA_LOG_OUTPUT( info_logger_, msg)
 
#define WLOG_OUTPUT(msg)   SPARTA_LOG_OUTPUT( warn_logger_, msg)
 
#define SPARTA_LOG(logger, msg)   SPARTA_LOG_CODE_BLOCK(logger, SPARTA_LOG_OUTPUT(logger, msg))
 
#define DLOG(msg)   SPARTA_LOG(debug_logger_, msg)
 
#define ILOG(msg)   SPARTA_LOG( info_logger_, msg)
 
#define WLOG(msg)   SPARTA_LOG( warn_logger_, msg)
 
#define SPARTA_LOG_IF(logger, condition, msg)
 
#define DLOG_IF(condition, msg)   SPARTA_LOG_IF(debug_logger_, condition, msg)
 
#define ILOG_IF(condition, msg)   SPARTA_LOG_IF( info_logger_, condition, msg)
 
#define WLOG_IF(condition, msg)   SPARTA_LOG_IF( warn_logger_, condition, msg)
 

Detailed Description

These macros are meant to be used within a method within a class that derives from sparta::Unit to simplify sending messages to the debug, info, and warn loggers defined in the sparta::Unit base class.

Example usage:

class Fetch : public sparta::Unit
{
    void FetchSomeInsts() const {
        const int val = 5;
        DLOG("Got " << val << " instructions");
    }
}

Example debug logger output:

{0000000000 00000000 top.fetch debug} FetchSomeInsts: Got 5 instructions

Macro Definition Documentation

◆ DLOG

#define DLOG (   msg)    SPARTA_LOG(debug_logger_, msg)

Definition at line 90 of file LogUtils.hpp.

◆ DLOG_CODE_BLOCK

#define DLOG_CODE_BLOCK (   code)    SPARTA_LOG_CODE_BLOCK(debug_logger_, code)

Definition at line 55 of file LogUtils.hpp.

◆ DLOG_IF

#define DLOG_IF (   condition,
  msg 
)    SPARTA_LOG_IF(debug_logger_, condition, msg)

Definition at line 111 of file LogUtils.hpp.

◆ DLOG_OUTPUT

#define DLOG_OUTPUT (   msg)    SPARTA_LOG_OUTPUT(debug_logger_, msg)

Definition at line 71 of file LogUtils.hpp.

◆ ILOG

#define ILOG (   msg)    SPARTA_LOG( info_logger_, msg)

Definition at line 94 of file LogUtils.hpp.

◆ ILOG_CODE_BLOCK

#define ILOG_CODE_BLOCK (   code)    SPARTA_LOG_CODE_BLOCK( info_logger_, code)

Definition at line 59 of file LogUtils.hpp.

◆ ILOG_IF

#define ILOG_IF (   condition,
  msg 
)    SPARTA_LOG_IF( info_logger_, condition, msg)

Definition at line 115 of file LogUtils.hpp.

◆ ILOG_OUTPUT

#define ILOG_OUTPUT (   msg)    SPARTA_LOG_OUTPUT( info_logger_, msg)

Definition at line 75 of file LogUtils.hpp.

◆ SPARTA_LOG

#define SPARTA_LOG (   logger,
  msg 
)    SPARTA_LOG_CODE_BLOCK(logger, SPARTA_LOG_OUTPUT(logger, msg))

Macro to simplify sending messages to the Unit logger

Parameters
msgThe message to send to the logger

Definition at line 86 of file LogUtils.hpp.

◆ SPARTA_LOG_CODE_BLOCK

#define SPARTA_LOG_CODE_BLOCK (   logger,
  code 
)
Value:
if (SPARTA_EXPECT_FALSE(logger)) { \
code \
}
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.

The main motivation for decomposition into *LOG_CODE_BLOCK and *LOG_OUTPUT is to support something like the following:

DLOG_CODE_BLOCK( std::ostringstream oss; // Complex sequence of various outputs to the ostringstream // ... DLOG_OUTPUT(oss.str()); )

The preprocessor can then still completely eliminate a complex logging message like this if SPARTA_DISABLE_MACRO_LOGGING is defined. It also allows a complex logging message to have consistent format with all other logging messages.

Definition at line 47 of file LogUtils.hpp.

◆ SPARTA_LOG_IF

#define SPARTA_LOG_IF (   logger,
  condition,
  msg 
)
Value:
if (condition) { \
SPARTA_LOG_OUTPUT(logger, msg) \
} \
)
#define SPARTA_LOG_CODE_BLOCK(logger, code)
Definition LogUtils.hpp:47

Definition at line 102 of file LogUtils.hpp.

◆ SPARTA_LOG_OUTPUT

#define SPARTA_LOG_OUTPUT (   logger,
  msg 
)    logger << __func__ << ": " << msg;

Definition at line 67 of file LogUtils.hpp.

◆ WLOG

#define WLOG (   msg)    SPARTA_LOG( warn_logger_, msg)

Definition at line 98 of file LogUtils.hpp.

◆ WLOG_CODE_BLOCK

#define WLOG_CODE_BLOCK (   code)    SPARTA_LOG_CODE_BLOCK( warn_logger_, code)

Definition at line 63 of file LogUtils.hpp.

◆ WLOG_IF

#define WLOG_IF (   condition,
  msg 
)    SPARTA_LOG_IF( warn_logger_, condition, msg)

Definition at line 119 of file LogUtils.hpp.

◆ WLOG_OUTPUT

#define WLOG_OUTPUT (   msg)    SPARTA_LOG_OUTPUT( warn_logger_, msg)

Definition at line 79 of file LogUtils.hpp.