17 #ifndef _SCC_REPORT_H_
18 #define _SCC_REPORT_H_
20 #include "utilities.h"
21 #include <cci_configuration>
27 #include <sysc/kernel/sc_time.h>
28 #include <sysc/utils/sc_report.h>
29 #include <unordered_map>
30 #include <util/ities.h>
32 #if defined(_MSC_VER) && defined(ERROR)
77 #define SCC_LOG_LEVEL_PARAM_NAME "log_level"
85 enum class log { NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, TRACEALL, DBGTRACE = TRACEALL };
88 static std::array<const char* const, 8> log_level_names = {{
"NONE",
"FATAL",
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"TRACE",
"TRACEALL"}};
89 static const std::unordered_map<std::string, scc::log> log_level_lut = {
90 {
"NONE", scc::log::NONE}, {
"FATAL", scc::log::FATAL}, {
"ERROR", scc::log::ERROR}, {
"WARNING", scc::log::WARNING},
91 {
"INFO", scc::log::INFO}, {
"DEBUG", scc::log::DEBUG}, {
"TRACE", scc::log::TRACE}, {
"TRACEALL", scc::log::TRACEALL}};
101 assert(logLevel >=
static_cast<int>(log::NONE) && logLevel <=
static_cast<int>(log::TRACEALL));
102 std::array<const log, 8> m = {{log::NONE, log::FATAL, log::ERROR, log::WARNING, log::INFO, log::DEBUG, log::TRACE, log::TRACEALL}};
116 auto it = scc::log_level_lut.find(buf);
117 if(it == std::end(scc::log_level_lut))
118 throw std::out_of_range(std::string(
"Illegal log level value: ") + buf);
131 os << log_level_names[static_cast<unsigned>(val)];
142 void init_logging(
log level = log::WARNING,
unsigned type_field_width = 24,
bool print_time =
false);
148 void reinit_logging();
155 void reinit_logging(
log level);
163 log level{log::WARNING};
164 unsigned msg_type_field_width{24};
165 bool print_sys_time{
false};
166 bool print_sim_time{
true};
167 bool print_delta{
false};
168 bool print_severity{
true};
169 bool colored_output{
true};
170 std::string log_file_name{
""};
171 std::string log_filter_regex{
""};
172 bool log_async{
true};
173 bool dont_create_broker{
false};
174 bool report_only_first_error{
false};
175 bool instance_based_log_levels{
true};
176 bool install_handler{
true};
319 return static_cast<sc_core::sc_verbosity
>(::sc_core::sc_report_handler::get_verbosity_level());
351 template <sc_core::sc_severity SEVERITY>
struct ScLogger {
360 ScLogger(
const char* file,
int line,
int verbosity = sc_core::SC_MEDIUM)
364 , level(verbosity){};
380 virtual ~ScLogger() { ::sc_core::sc_report_handler::report(SEVERITY, t ? t :
"SystemC", os.str().c_str(), level, file, line); }
399 this->t =
const_cast<char*
>(t);
410 this->t =
const_cast<char*
>(t.c_str());
419 inline std::ostream&
get() {
return os; };
422 std::ostringstream os{};
433 #define SCCLOG(lvl, ...) ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, lvl).type(__VA_ARGS__).get()
435 #define SCCTRACEALL(...) \
436 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_DEBUG) \
437 SCCLOG(sc_core::SC_DEBUG, __VA_ARGS__)
439 #define SCCTRACE(...) \
440 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_FULL) \
441 SCCLOG(sc_core::SC_FULL, __VA_ARGS__)
443 #define SCCDEBUG(...) \
444 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_HIGH) \
445 SCCLOG(sc_core::SC_HIGH, __VA_ARGS__)
447 #define SCCINFO(...) \
448 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_MEDIUM) \
449 SCCLOG(sc_core::SC_MEDIUM, __VA_ARGS__)
451 #define SCCWARN(...) \
452 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_LOW) \
453 ::scc::ScLogger<::sc_core::SC_WARNING>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
455 #define SCCERR(...) ::scc::ScLogger<::sc_core::SC_ERROR>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
457 #define SCCFATAL(...) ::scc::ScLogger<::sc_core::SC_FATAL>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
460 #define SCC_ASSERT(expr) ((void)0)
462 #define SCC_ASSERT(expr) ((void)((expr) ? 0 : (SC_REPORT_FATAL(::sc_core::SC_ID_ASSERTION_FAILED_, #expr), 0)))
465 #define SCMOD this->name()
505 std::streamsize xsputn(
const char_type* s, std::streamsize n)
override;
509 std::streambuf* old_buf{
nullptr};
515 template <>
inline bool cci_value_converter<scc::log>::pack(cci_value::reference dst,
scc::log const& src) {
516 dst.set_string(scc::log_level_names[
static_cast<unsigned>(src)]);
519 template <>
inline bool cci_value_converter<scc::log>::unpack(
scc::log& dst, cci_value::const_reference src) {
523 auto it = scc::log_level_lut.find(src.get_string());
524 if(it != std::end(scc::log_level_lut)) {
~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)