fix event fun
This commit is contained in:
@@ -50,19 +50,16 @@ extern std::string subdir;
|
|||||||
//日志主题
|
//日志主题
|
||||||
extern std::string G_LOG_TOPIC;
|
extern std::string G_LOG_TOPIC;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////
|
||||||
|
/* log4.cpp 顶部 */
|
||||||
|
#if __cplusplus >= 201103L
|
||||||
|
thread_local int g_log_code_tls = 0;
|
||||||
|
#else
|
||||||
|
__thread int g_log_code_tls = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////辅助函数
|
////////////////////////////////////////////////////////辅助函数
|
||||||
/*std::string get_front_type_from_subdir() {
|
|
||||||
if (subdir == "cfg_3s_data")
|
|
||||||
return "realTime";
|
|
||||||
else if (subdir == "cfg_soe_comtrade")
|
|
||||||
return "comtrade";
|
|
||||||
else if (subdir == "cfg_recallhis_data")
|
|
||||||
return "recall";
|
|
||||||
else if (subdir == "cfg_stat_data")
|
|
||||||
return "stat";
|
|
||||||
else
|
|
||||||
return "unknown";
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// 递归创建目录
|
// 递归创建目录
|
||||||
bool create_directory_recursive(const std::string& path) {
|
bool create_directory_recursive(const std::string& path) {
|
||||||
@@ -129,10 +126,6 @@ bool DebugSwitch::match(const std::string& logger_name, int level, int logtype)
|
|||||||
std::map<std::string, TypedLogger> logger_map;
|
std::map<std::string, TypedLogger> logger_map;
|
||||||
DebugSwitch g_debug_switch;
|
DebugSwitch g_debug_switch;
|
||||||
|
|
||||||
// ★新增:定义 TLS 变量,默认 0
|
|
||||||
|
|
||||||
thread_local int g_log_code_tls = 0;
|
|
||||||
|
|
||||||
class SendAppender : public Appender {
|
class SendAppender : public Appender {
|
||||||
protected:
|
protected:
|
||||||
void append(const spi::InternalLoggingEvent& event) {
|
void append(const spi::InternalLoggingEvent& event) {
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
#ifndef LOG4_H
|
#ifndef LOG4_H
|
||||||
#define LOG4_H
|
#define LOG4_H
|
||||||
|
|
||||||
|
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||||
|
#define LOG_TLS_SPEC thread_local
|
||||||
|
#else
|
||||||
|
/* C 或旧编译器,走 GCC 扩展 */
|
||||||
|
#define LOG_TLS_SPEC __thread
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ★统一的对外声明(别在其他头/源里再声明不同版本!) */
|
||||||
|
extern LOG_TLS_SPEC int g_log_code_tls;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -73,7 +83,8 @@ void process_log_command(const std::string& id, const std::string& level, const
|
|||||||
|
|
||||||
void update_log_entries_countdown();
|
void update_log_entries_countdown();
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
void remove_loggers_by_terminal_id(const std::string& terminal_id_cstr);
|
void remove_loggers_by_terminal_id(const std::string& terminal_id_cstr);
|
||||||
void init_logger_process();
|
void init_logger_process();
|
||||||
void init_loggers();
|
void init_loggers();
|
||||||
@@ -91,7 +102,7 @@ void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...);
|
|||||||
// 说明:使用编译器的 TLS(__thread)保存当前日志的 code 值。
|
// 说明:使用编译器的 TLS(__thread)保存当前日志的 code 值。
|
||||||
// 在每次打日志前写入,打完后恢复,Appender 读取该值写入 JSON。
|
// 在每次打日志前写入,打完后恢复,Appender 读取该值写入 JSON。
|
||||||
|
|
||||||
extern int g_log_code_tls; // 声明为 TLS 变量,定义见 log4.cpp
|
|
||||||
// ====================== ★新增结束 ======================
|
// ====================== ★新增结束 ======================
|
||||||
|
|
||||||
|
|
||||||
@@ -151,7 +162,10 @@ typedef enum LogCode {
|
|||||||
LOG_CODE_SPACE_ALARM = 700 /* 空间告警 */
|
LOG_CODE_SPACE_ALARM = 700 /* 空间告警 */
|
||||||
} LogCode;
|
} LogCode;
|
||||||
|
|
||||||
#endif // __cplusplus
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user