Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

避免kBroadcastLogEvent被外部引用新增接口,Assert_Throw实现从zlmediakit迁移置此,两者均依赖 #236

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/Util/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
2 changes: 2 additions & 0 deletions src/Util/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/Util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
15 changes: 15 additions & 0 deletions src/Util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ class ObjectStatistic{
return instance; \
}

class AssertFailedException : public std::runtime_error {
public:
template<typename ...T>
AssertFailedException(T && ...args) : std::runtime_error(std::forward<T>(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);
Expand Down Expand Up @@ -432,4 +438,13 @@ class AnyStorage : public std::unordered_map<std::string, Any> {
};

} // 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_ */
Loading