17 #ifndef _SCC_REPORT_H_
18 #define _SCC_REPORT_H_
20 #include "utilities.h"
25 #include <sysc/kernel/sc_time.h>
26 #include <sysc/utils/sc_report.h>
27 #include <util/ities.h>
29 #if defined(_MSC_VER) && defined(ERROR)
74 #define SCC_LOG_LEVEL_PARAM_NAME "log_level"
82 static std::array<const char* const, 8> buffer = {{
"NONE",
"FATAL",
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"TRACE",
"TRACEALL"}};
84 enum class log { NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, TRACEALL, DBGTRACE = TRACEALL };
93 assert(logLevel >=
static_cast<int>(log::NONE) && logLevel <=
static_cast<int>(log::TRACEALL));
94 std::array<const log, 8> m = {{log::NONE, log::FATAL, log::ERROR, log::WARNING, log::INFO, log::DEBUG, log::TRACE, log::TRACEALL}};
108 for(
auto i = 0U; i <= static_cast<unsigned>(log::TRACEALL); ++i) {
109 if(std::strcmp(buf.c_str(), buffer[i]) == 0) {
125 os << buffer[static_cast<unsigned>(val)];
136 void init_logging(
log level = log::WARNING,
unsigned type_field_width = 24,
bool print_time =
false);
145 void reinit_logging(
log level = log::WARNING);
153 log level{log::WARNING};
154 unsigned msg_type_field_width{24};
155 bool print_sys_time{
false};
156 bool print_sim_time{
true};
157 bool print_delta{
false};
158 bool print_severity{
true};
159 bool colored_output{
true};
160 std::string log_file_name{
""};
161 std::string log_filter_regex{
""};
162 bool log_async{
true};
163 bool dont_create_broker{
false};
164 bool report_only_first_error{
false};
165 bool instance_based_log_levels{
true};
166 bool install_handler{
true};
309 return static_cast<sc_core::sc_verbosity
>(::sc_core::sc_report_handler::get_verbosity_level());
341 template <sc_core::sc_severity SEVERITY>
struct ScLogger {
350 ScLogger(
const char* file,
int line,
int verbosity = sc_core::SC_MEDIUM)
354 , level(verbosity){};
370 virtual ~ScLogger() { ::sc_core::sc_report_handler::report(SEVERITY, t ? t :
"SystemC", os.str().c_str(), level, file, line); }
389 this->t =
const_cast<char*
>(t);
400 this->t =
const_cast<char*
>(t.c_str());
409 inline std::ostream&
get() {
return os; };
412 std::ostringstream os{};
423 #define SCCLOG(lvl, ...) ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, lvl / 10).type(__VA_ARGS__).get()
425 #define SCCTRACEALL(...) \
426 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_DEBUG) \
427 SCCLOG(sc_core::SC_DEBUG, __VA_ARGS__)
429 #define SCCTRACE(...) \
430 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_FULL) \
431 SCCLOG(sc_core::SC_FULL, __VA_ARGS__)
433 #define SCCDEBUG(...) \
434 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_HIGH) \
435 SCCLOG(sc_core::SC_HIGH, __VA_ARGS__)
437 #define SCCINFO(...) \
438 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_MEDIUM) \
439 SCCLOG(sc_core::SC_MEDIUM, __VA_ARGS__)
441 #define SCCWARN(...) \
442 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_LOW) \
443 ::scc::ScLogger<::sc_core::SC_WARNING>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
445 #define SCCERR(...) ::scc::ScLogger<::sc_core::SC_ERROR>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
447 #define SCCFATAL(...) ::scc::ScLogger<::sc_core::SC_FATAL>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
450 #define SCC_ASSERT(expr) ((void)0)
452 #define SCC_ASSERT(expr) ((void)((expr) ? 0 : (SC_REPORT_FATAL(::sc_core::SC_ID_ASSERTION_FAILED_, #expr), 0)))
455 #define SCMOD this->name()
495 std::streamsize xsputn(
const char_type* s, std::streamsize n)
override;
499 std::streambuf* old_buf{
nullptr};
~stream_redirection()
destructor restoring the output stream buffer
void reset()
reset the stream redirection and restore output buffer of the stream
stream_redirection(std::ostream &os, log level)
constructor redirecting the given stream to a SystemC log message of given llog level
std::istream & operator>>(std::istream &is, log &val)
read a log level from input stream e.g. used by boost::lexical_cast
bool is_logging_initialized()
get the state of the SCC logging system
void set_logging_level(log level)
sets the SystemC logging level
void init_logging(log level=log::WARNING, unsigned type_field_width=24, bool print_time=false)
initializes the SystemC logging system with a particular logging level
log as_log(int logLevel)
safely convert an integer into a log level
log get_logging_level()
get the SystemC logging level
void set_cycle_base(sc_core::sc_time period)
sets the cycle base for cycle based logging
sc_core::sc_verbosity get_log_verbosity()
get the global verbosity level
std::ostream & operator<<(std::ostream &os, log const &val)
output the textual representation of the log level
log
enum defining the log levels
the configuration class for the logging setup
LogConfig & printSeverity(bool=true)
LogConfig & printSysTime(bool=true)
LogConfig & logFilterRegex(std::string &&)
LogConfig & reportOnlyFirstError(bool=true)
LogConfig & coloredOutput(bool=true)
LogConfig & dontCreateBroker(bool=true)
LogConfig & logLevel(log)
LogConfig & msgTypeFieldWidth(unsigned)
LogConfig & logFileName(const std::string &)
LogConfig & printSimTime(bool=true)
LogConfig & logAsync(bool=true)
LogConfig & printDelta(bool=true)
LogConfig & instanceBasedLogLevels(bool=true)
LogConfig & installHandler(bool=true)
LogConfig & logFilterRegex(const std::string &)
LogConfig & logFileName(std::string &&)
ScLogger & type(char const *t)
set the category of the log entry
virtual ~ScLogger()
the destructor generating the SystemC report
ScLogger & type(std::string const &t)
set the category of the log entry
std::ostream & get()
get the underlying ostringstream
ScLogger & type()
reset the category of the log entry
ScLogger(const char *file, int line, int verbosity=sc_core::SC_MEDIUM)