41#ifndef __BASE_LOGGING_HH__
42#define __BASE_LOGGING_HH__
100 template<
typename ...Args>
void
103 std::stringstream
ss;
105 const std::string str =
ss.str();
107 std::stringstream ss_formatted;
108 ss_formatted <<
prefix << str;
109 if (str.length() && str.back() !=
'\n' && str.back() !=
'\r')
110 ss_formatted << std::endl;
113 log(loc, ss_formatted.str());
116 template<
typename ...Args>
void
147 std::stringstream
ss;
149 std::string str = cb();
151 if (str.length() && str.back() !=
'\n' && str.back() !=
'\r')
161 std::cerr << loc.
file <<
":" << loc.
line <<
": " <<
s
173#define base_message(logger, ...) \
174 [&log = logger](const auto&... args) { \
175 log.print(::gem5::Logger::Loc(__FILE__, __LINE__), args...); \
186#define base_message_once(logger, ...) \
187 [&log = logger](const auto&... args) { \
188 static bool once{false}; \
189 if (GEM5_UNLIKELY(!once)) { \
191 base_message(log, args...); \
202#define exit_message(logger, ...) \
204 [&log = logger](const auto&... args) { \
205 base_message(log, args...); \
207 logger.exit_helper() \
220#define panic(...) exit_message(::gem5::Logger::getPanic(), __VA_ARGS__)
232#define fatal(...) exit_message(::gem5::Logger::getFatal(), __VA_ARGS__)
246#define panic_if(cond, ...) \
248 GEM5_UNLIKELY(static_cast<bool>(cond)) ? \
249 panic("panic condition " # cond " occurred: %s", \
250 ::gem5::csprintf(__VA_ARGS__)) : \
268#define fatal_if(cond, ...) \
270 GEM5_UNLIKELY(static_cast<bool>(cond)) ? \
271 fatal("fatal condition " # cond " occurred: %s", \
272 ::gem5::csprintf(__VA_ARGS__)) : \
288#define warn(...) base_message(::gem5::Logger::getWarn(), __VA_ARGS__)
289#define inform(...) base_message(::gem5::Logger::getInfo(), __VA_ARGS__)
290#define hack(...) base_message(::gem5::Logger::getHack(), __VA_ARGS__)
292#define warn_once(...) \
293 base_message_once(::gem5::Logger::getWarn(), __VA_ARGS__)
294#define inform_once(...) \
295 base_message_once(::gem5::Logger::getInfo(), __VA_ARGS__)
296#define hack_once(...) \
297 base_message_once(::gem5::Logger::getHack(), __VA_ARGS__)
315#define warn_if(cond, ...) \
317 static_cast<bool>(cond) ? \
318 warn(__VA_ARGS__) : \
322#define warn_if_once(cond, ...) \
324 static_cast<bool>(cond) ? \
325 warn_once(__VA_ARGS__) : \
332#define NDEBUG_DEFINED 1
334#define NDEBUG_DEFINED 0
349#define gem5_assert(cond, ...) \
351 GEM5_UNLIKELY(NDEBUG_DEFINED || static_cast<bool>(cond)) ? \
353 [](const auto&... args) { \
355 if constexpr (sizeof...(args) == 0) return ""; \
356 else return std::string(": ") + csprintf(args...); \
358 panic("assert(" #cond ") failed%s", msg()); \
364#define chatty_assert(...) \
366 gem5_assert(args...), \
367 GEM5_DEPRECATED_MACRO(chatty_assert, {}, "Please use gem5_assert()") \
virtual void log(const Loc &loc, std::string s)
Generates the log message.
static Logger & getWarn()
void registerExtraLog(std::function< std::string()> cb)
Register callback to generate extra log.
std::vector< std::function< std::string()> > extraLogs
Data structure to store extra log callbacks.
Logger(const char *prefix)
void print(const Loc &loc, const std::string &format, const Args &...args)
static Logger & getInfo()
static Logger & getHack()
void print(const Loc &loc, const char *format, const Args &...args)
std::string getFormattedExtraLog() const
Generate the formatted extra log string.
static Logger & getPanic()
Get a Logger for the specified type of message.
void exit_helper()
This helper is necessary since noreturn isn't inherited by virtual functions, and gcc will get mad if...
static Logger & getFatal()
static void setLevel(LogLevel ll)
Bitfield< 31, 29 > format
Copyright (c) 2024 Arm Limited All rights reserved.
void ccprintf(cp::Print &print)
Loc(const char *file, int line)