21#include <cci_configuration>
28#include <sysc/kernel/sc_time.h>
29#include <sysc/utils/sc_report.h>
30#include <unordered_map>
31#include <util/ities.h>
33#if defined(_MSC_VER) && defined(ERROR)
78#define SCC_LOG_LEVEL_PARAM_NAME "log_level"
86enum class log { NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, TRACEALL, DBGTRACE = TRACEALL };
89static std::array<const char* const, 8> log_level_names = {{
"NONE",
"FATAL",
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"TRACE",
"TRACEALL"}};
90static const std::unordered_map<std::string, scc::log> log_level_lut = {
91 {
"NONE", scc::log::NONE}, {
"FATAL", scc::log::FATAL}, {
"ERROR", scc::log::ERROR}, {
"WARNING", scc::log::WARNING},
92 {
"INFO", scc::log::INFO}, {
"DEBUG", scc::log::DEBUG}, {
"TRACE", scc::log::TRACE}, {
"TRACEALL", scc::log::TRACEALL}};
102 assert(logLevel >=
static_cast<int>(log::NONE) && logLevel <=
static_cast<int>(log::TRACEALL));
103 std::array<const log, 8> m = {{log::NONE, log::FATAL, log::ERROR, log::WARNING, log::INFO, log::DEBUG, log::TRACE, log::TRACEALL}};
117 auto it = scc::log_level_lut.find(buf);
118 if(it == std::end(scc::log_level_lut))
119 throw std::out_of_range(std::string(
"Illegal log level value: ") + buf);
132 os << log_level_names[static_cast<unsigned>(val)];
143void init_logging(
log level = log::WARNING,
unsigned type_field_width = 24,
bool print_time =
false);
149void reinit_logging();
156void reinit_logging(
log level);
164 log level{log::WARNING};
165 unsigned msg_type_field_width{24};
166 bool print_sys_time{
false};
167 bool print_sim_time{
true};
168 bool print_delta{
false};
169 bool print_severity{
true};
170 bool colored_output{
true};
171 std::string log_file_name{
""};
172 std::string log_filter_regex{
""};
173 bool log_async{
true};
174 bool dont_create_broker{
false};
175 bool report_only_first_error{
false};
176 bool instance_based_log_levels{
true};
177 bool install_handler{
true};
325 return static_cast<sc_core::sc_verbosity
>(::sc_core::sc_report_handler::get_verbosity_level());
357template <sc_core::sc_severity SEVERITY>
struct ScLogger {
366 ScLogger(
const char* file,
int line,
int verbosity = sc_core::SC_MEDIUM)
370 , level(verbosity){};
388 auto verb = ::sc_core::sc_report_handler::set_verbosity_level(1000);
389 ::sc_core::sc_report_handler::report(SEVERITY, t ? t :
"SystemC", os.str().c_str(), level, file, line);
390 ::sc_core::sc_report_handler::set_verbosity_level(verb);
410 this->t =
const_cast<char*
>(t);
421 this->t =
const_cast<char*
>(t.c_str());
430 inline std::ostream&
get() {
return os; };
433 std::ostringstream os{};
444#define SCCLOG(lvl, ...) ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, lvl).type(__VA_ARGS__).get()
446#define SCCTRACEALL(...) \
447 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_DEBUG) \
448 SCCLOG(sc_core::SC_DEBUG, __VA_ARGS__)
450#define SCCTRACE(...) \
451 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_FULL) \
452 SCCLOG(sc_core::SC_FULL, __VA_ARGS__)
454#define SCCDEBUG(...) \
455 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_HIGH) \
456 SCCLOG(sc_core::SC_HIGH, __VA_ARGS__)
458#define SCCINFO(...) \
459 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_MEDIUM) \
460 SCCLOG(sc_core::SC_MEDIUM, __VA_ARGS__)
462#define SCCWARN(...) \
463 if(::scc::get_log_verbosity(__VA_ARGS__) >= sc_core::SC_LOW) \
464 ::scc::ScLogger<::sc_core::SC_WARNING>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
466#define SCCERR(...) ::scc::ScLogger<::sc_core::SC_ERROR>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
468#define SCCFATAL(...) ::scc::ScLogger<::sc_core::SC_FATAL>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
471#define SCC_ASSERT(expr) ((void)0)
473#define SCC_ASSERT(expr) ((void)((expr) ? 0 : (SC_REPORT_FATAL(::sc_core::SC_ID_ASSERTION_FAILED_, #expr), 0)))
477#define SCMOD this->name()
480#define SCOBJ this->name()
521 std::streamsize xsputn(
const char_type* s, std::streamsize n)
override;
525 std::streambuf* old_buf{
nullptr};
531template <>
inline bool cci_value_converter<scc::log>::pack(cci_value::reference dst,
scc::log const& src) {
532 dst.set_string(scc::log_level_names[
static_cast<unsigned>(src)]);
535template <>
inline bool cci_value_converter<scc::log>::unpack(
scc::log& dst, cci_value::const_reference src) {
539 auto it = scc::log_level_lut.find(src.get_string());
540 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
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
bool is_logging_initialized()
get the state of the SCC logging system
void set_cycle_base(sc_core::sc_time period)
sets the cycle base for cycle based logging
log get_logging_level()
get the SystemC logging level
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
std::mutex verbosity_mtx
a mutex needed to syncronize verbosity manipulations
the configuration class for the logging setup
LogConfig & printSeverity(bool=true)
LogConfig & printSysTime(bool=true)
LogConfig & reportOnlyFirstError(bool=true)
LogConfig & coloredOutput(bool=true)
LogConfig & logFileName(std::string &&)
LogConfig & dontCreateBroker(bool=true)
LogConfig & logFilterRegex(const std::string &)
LogConfig & logFileName(const std::string &)
LogConfig & logLevel(log)
LogConfig & msgTypeFieldWidth(unsigned)
LogConfig & printSimTime(bool=true)
LogConfig & logAsync(bool=true)
LogConfig & printDelta(bool=true)
LogConfig & instanceBasedLogLevels(bool=true)
LogConfig & installHandler(bool=true)
LogConfig & logFilterRegex(std::string &&)
ScLogger & type(char const *t)
set the category of the log entry
virtual ~ScLogger() noexcept(false)
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)