From fe8e2a773207be2a9c777788712a3bb3f006566c Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 28 Jan 2017 03:50:35 +0100 Subject: [PATCH] Logging enhancement for Joakim. For netlist device debugging one can now use #define LOG(...) log().info(__VA_ARGS__) to use debugging and the known #define LOG(...) do {} while (0) do disable debugging on device level. To avoid bitrot one could as well use #define LOG(...) log().info.log(__VA_ARGS__) and #define LOG(...) log().info.log(__VA_ARGS__) The later disables debugging. If the compiler can assume that there are no side effects from e.g. using foo(a/b), 'LOG("abc {1:04x}", foo(a/b));' should be completely optimized away. Log channels available are info, verbose, warning, error and fatal. Don't use debug, it is enabled only on specific debug builds. Use would be e.g. LOG("abc {1:04x}", 2); The format specifier in the string are enclosed in "{}". "{2}" is the second parameter after the format string. Types are determined automatically. "{3:04x}" would format a number as a hexadecimal with 4 leading zeros. [Couriersud] --- src/lib/netlist/plib/pfmtlog.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 1a212e601b8..681607bddc0 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -192,6 +192,13 @@ public: explicit pfmt_writer_t() : m_enabled(true) { } virtual ~pfmt_writer_t() { } + /* runtime enable */ + template + void log(const pstring fmt, Args&&... args) const + { + if (build_enabled && enabled && m_enabled) (*this)(fmt, std::forward(args)...); + } + void operator ()(const pstring fmt) const { if (build_enabled && m_enabled) vdowrite(fmt);