summaryrefslogtreecommitdiff
path: root/runtime/onert/core/include/util/logging.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/onert/core/include/util/logging.h')
-rw-r--r--runtime/onert/core/include/util/logging.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/runtime/onert/core/include/util/logging.h b/runtime/onert/core/include/util/logging.h
index 76cfb8d60..fe255f8ff 100644
--- a/runtime/onert/core/include/util/logging.h
+++ b/runtime/onert/core/include/util/logging.h
@@ -18,6 +18,7 @@
#define __ONERT_UTIL_LOGGING_H__
#include <iostream>
+#include <cstring>
#include "util/ConfigSource.h"
@@ -52,16 +53,34 @@ private:
static Context &ctx = Context::get();
+inline std::string decorated_name(const char *input)
+{
+ const int min_prefix = 16;
+ std::string prefix(input);
+ auto len_prefix = prefix.size();
+ if (len_prefix > min_prefix)
+ return "[" + prefix + "] ";
+ std::string spaces((min_prefix - len_prefix) / 2, ' ');
+ return (len_prefix % 2 ? "[ " : "[") + spaces + prefix + spaces + "] ";
+}
+
} // namespace logging
} // namespace util
} // namespace onert
#define VERBOSE(name) \
if (::onert::util::logging::ctx.enabled()) \
- std::cout << "[" << #name << "] "
+ std::cout << ::onert::util::logging::decorated_name(#name)
#define VERBOSE_F() \
if (::onert::util::logging::ctx.enabled()) \
- std::cout << "[" << __func__ << "] "
+ std::cout << ::onert::util::logging::decorated_name(__func__)
+
+#define WHEN_LOG_ENABLED(METHOD) \
+ if (::onert::util::logging::ctx.enabled()) \
+ do \
+ { \
+ METHOD; \
+ } while (0)
#endif // __ONERT_UTIL_LOGGING_H__