|
@@ -0,0 +1,28 @@
|
|
|
+// LogLocalHelper.h
|
|
|
+#ifndef LOG_LOCAL_HELPER_H
|
|
|
+#define LOG_LOCAL_HELPER_H
|
|
|
+#include <string>
|
|
|
+#include "Log4CPP.h"
|
|
|
+
|
|
|
+void TiRaySetLocalModuleName(const std::string& moduleName);
|
|
|
+const std::string& TiRayGetLocalModuleName();
|
|
|
+
|
|
|
+// 重定义日志宏:使用当前动态库的局部模块名getLocalModuleName()
|
|
|
+#define LOG(level, format, ...) \
|
|
|
+ do { \
|
|
|
+ const std::string& localModule = TiRayGetLocalModuleName(); \
|
|
|
+ LogInstance* logger = LogManager::getInstance().getInstance(localModule); \
|
|
|
+ if (logger && logger->isInitialized()) { \
|
|
|
+ logger->log(log4cpp::Priority::level, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__); \
|
|
|
+ } else { \
|
|
|
+ std::cerr << "[" << localModule << "] Logger not initialized or module not found!" << std::endl; \
|
|
|
+ } \
|
|
|
+ } while(0)
|
|
|
+
|
|
|
+// 保留原有的级别宏(无需修改,依赖重定义后的LOG)
|
|
|
+#define FDEBUG(format, ...) LOG(DEBUG, format, ##__VA_ARGS__)
|
|
|
+#define FINFO(format, ...) LOG(INFO, format, ##__VA_ARGS__)
|
|
|
+#define FWARN(format, ...) LOG(WARN, format, ##__VA_ARGS__)
|
|
|
+#define FERROR(format, ...) LOG(ERROR, format, ##__VA_ARGS__)
|
|
|
+
|
|
|
+#endif // LOG_LOCAL_HELPER_H
|