Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Shorten the file name in log message #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion libcoz/ccutil/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ 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)
# define LOG(color, exit) (ccutil::logger(exit) << color)
# 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
Expand Down