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<true>(__VA_ARGS__)
and
	#define LOG(...) log().info.log<false>(__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]
This commit is contained in:
couriersud 2017-01-28 03:50:35 +01:00
parent 4eee6b09a9
commit fe8e2a7732

View File

@ -192,6 +192,13 @@ public:
explicit pfmt_writer_t() : m_enabled(true) { }
virtual ~pfmt_writer_t() { }
/* runtime enable */
template<bool enabled, typename... Args>
void log(const pstring fmt, Args&&... args) const
{
if (build_enabled && enabled && m_enabled) (*this)(fmt, std::forward<Args>(args)...);
}
void operator ()(const pstring fmt) const
{
if (build_enabled && m_enabled) vdowrite(fmt);