From a5e3406f616157e113757faee9440ac3452b4f41 Mon Sep 17 00:00:00 2001 From: condy Date: Thu, 12 Jan 2023 03:29:35 +0800 Subject: [PATCH] Shorten the file name in log message --- libcoz/ccutil/log.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libcoz/ccutil/log.h b/libcoz/ccutil/log.h index fdf0b6c..e9969bf 100644 --- a/libcoz/ccutil/log.h +++ b/libcoz/ccutil/log.h @@ -61,6 +61,12 @@ namespace ccutil { return std::move(*this); } }; + + constexpr const char* basename(const char* s, std::size_t i = 0, std::size_t pos = 0) { + return s[i] == '\0' ? s + pos + : s[i] == '/' ? basename(s, i+1, i+1) + : basename(s, i+1, pos); + } } #if defined(NDEBUG) @@ -68,7 +74,7 @@ namespace ccutil { # define INFO (ccutil::logger_base()) # define ASSERT(cond) (ccutil::logger_base()) #else -# define LOG(color, exit) (ccutil::logger(exit) << ccutil::SourceColor << "[" << __FILE__ << ":" << __LINE__ << "] " << color) +# define LOG(color, exit) (ccutil::logger(exit) << ccutil::SourceColor << "[" << ccutil::basename(__FILE__) << ":" << __LINE__ << "] " << color) # define INFO LOG(ccutil::InfoColor, false) # define ASSERT(cond) (cond) ? ccutil::logger_base() : FATAL #endif