diff --git a/src/Util/logger.cpp b/src/Util/logger.cpp index 9be4e8be..fc82c831 100644 --- a/src/Util/logger.cpp +++ b/src/Util/logger.cpp @@ -283,6 +283,8 @@ void EventChannel::write(const Logger &logger, const LogContextPtr &ctx) { NOTICE_EMIT(BroadcastLogEventArgs, kBroadcastLogEvent, logger, ctx); } +const std::string &EventChannel::getBroadcastLogEventName() { return kBroadcastLogEvent;} + ///////////////////ConsoleChannel/////////////////// ConsoleChannel::ConsoleChannel(const string &name, LogLevel level) : LogChannel(name, level) {} diff --git a/src/Util/logger.h b/src/Util/logger.h index 191a21c9..b8867355 100644 --- a/src/Util/logger.h +++ b/src/Util/logger.h @@ -243,6 +243,8 @@ class EventChannel : public LogChannel { public: //输出日志时的广播名 static const std::string kBroadcastLogEvent; + //toolkit目前仅只有一处全局变量被外部引用,减少导出相关定义,导出以下函数避免导出kBroadcastLogEvent + static const std::string& getBroadcastLogEventName(); //日志广播参数类型和列表 #define BroadcastLogEventArgs const Logger &logger, const LogContextPtr &ctx diff --git a/src/Util/util.cpp b/src/Util/util.cpp index e63b9c92..43396b45 100644 --- a/src/Util/util.cpp +++ b/src/Util/util.cpp @@ -650,3 +650,17 @@ void Creator::onDestoryException(const type_info &info, const exception &ex) { } // namespace toolkit + +extern "C" { +void Assert_Throw(int failed, const char *exp, const char *func, const char *file, int line, const char *str) { + if (failed) { + toolkit::_StrPrinter printer; + printer << "Assertion failed: (" << exp ; + if(str && *str){ + printer << ", " << str; + } + printer << "), function " << func << ", file " << file << ", line " << line << "."; + throw toolkit::AssertFailedException(printer); + } +} +} \ No newline at end of file diff --git a/src/Util/util.h b/src/Util/util.h index 1d53cc9c..158d6b9b 100644 --- a/src/Util/util.h +++ b/src/Util/util.h @@ -195,6 +195,12 @@ class ObjectStatistic{ return instance; \ } +class AssertFailedException : public std::runtime_error { +public: + template + AssertFailedException(T && ...args) : std::runtime_error(std::forward(args)...) {} +}; + std::string makeRandStr(int sz, bool printable = true); std::string hexdump(const void *buf, size_t len); std::string hexmem(const void* buf, size_t len); @@ -432,4 +438,13 @@ class AnyStorage : public std::unordered_map { }; } // namespace toolkit + +#ifdef __cplusplus +extern "C" { +#endif +extern void Assert_Throw(int failed, const char *exp, const char *func, const char *file, int line, const char *str); +#ifdef __cplusplus +} +#endif + #endif /* UTIL_UTIL_H_ */