更新:1、修改日志组件,使用spdlog日志库;
Signed-off-by: waiwaylee <waiwaylee@foxmail.com>
This commit is contained in:
@@ -87,7 +87,7 @@ int Data_Process::data_preprocess(struct DataRev Data_Input[150])
|
||||
{
|
||||
circle_id++;
|
||||
// std::cout << Data_Input[0].CPI_time << std::endl;
|
||||
// RDP_LOG<<"CPI_time: "<<Data_Input[0].CPI_time<<std::endl;
|
||||
// RDP_LOG_DEBUG("CPI_time: {}", Data_Input[0].CPI_time);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -249,11 +249,11 @@ int Data_Process::parameters_reload(const char* parameter_file_path)
|
||||
// rdp_parameter_load 仅在完整校验通过后写入目标对象,失败时保持原参数不变
|
||||
if (rdp_parameter_load(parameter_file_path, rdp_parameter, &error) != 0)
|
||||
{
|
||||
RDP_LOG << "parameters_reload failed: " << error << std::endl;
|
||||
RDP_LOG_ERROR("parameters_reload failed: {}", error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
RDP_LOG << "parameters_reload ok: " << parameter_file_path << std::endl;
|
||||
RDP_LOG_INFO("parameters_reload ok: {}", parameter_file_path != nullptr ? parameter_file_path : "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ int Data_Process:: track_delete(int delete_track_num, //手动
|
||||
{
|
||||
|
||||
trust_track[j].manual_delete_flag=1;
|
||||
// RDP_LOG << "Delete :" << trust_track[j].Track_Index << std::endl;
|
||||
// RDP_LOG_DEBUG("Delete : {}", trust_track[j].Track_Index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ Data_process_class_dll *Data_Process_Factory::GetB()
|
||||
{
|
||||
if(!p)
|
||||
{
|
||||
//初始化日志输出:RDP_LOG_ENABLE 开启时重定向 std::cout 到日志文件
|
||||
//rdp_log::Init();
|
||||
//初始化日志输出:标准输出 + 日志文件(.\rdp_logs\rdp_YYYYMMDD_HHMMSS.log)
|
||||
rdp_log::Init();
|
||||
|
||||
//初始化数据记录:RDP_DATA_RECORD 开启时创建记录目录、打开本次运行的记录库;
|
||||
//关闭时 rdp_record::Init() 为空实现,不产生任何开销
|
||||
@@ -42,10 +42,10 @@ void Data_Process_Factory::Destroy()
|
||||
delete p;
|
||||
p = nullptr;
|
||||
|
||||
//恢复 std::cout 到控制台并关闭日志文件
|
||||
//rdp_log::Shutdown();
|
||||
|
||||
//关闭记录库(RDP_DATA_RECORD 关闭时为空实现)
|
||||
rdp_record::Shutdown();
|
||||
|
||||
//flush 并关闭日志文件(须在记录模块关闭之后:其 Shutdown 仍会写日志)
|
||||
rdp_log::Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,15 @@
|
||||
STRINGIFY(PATCH_VERSION) "." \
|
||||
VERSION_INFO
|
||||
|
||||
/**********************************日志输出开关**********************************************/
|
||||
// 日志文件输出功能开关:
|
||||
// 1) 定义(默认)RDP_LOG_ENABLE:启用日志文件输出 —— 调用 Data_Process_Factory::GetB()
|
||||
// 时自动将 std::cout 重定向到日志文件,日志文件存放于 RDP_LOG_DIR 目录,
|
||||
// 文件名按当前日期+时间自动命名(如 rdp_20240826_153000.log);
|
||||
// 2) 注释掉 RDP_LOG_ENABLE:关闭 —— 不做重定向,日志仍输出到标准输出(控制台)。
|
||||
// #define RDP_LOG_ENABLE
|
||||
/**********************************日志输出*************************************************/
|
||||
// 日志基于内置 spdlog v1.17.0(third_party/spdlog,来源见其 UPSTREAM.md):
|
||||
// 1) 每次调用 Data_Process_Factory::GetB() 创建实例时,rdp_log::Init() 同时输出到
|
||||
// 标准输出与日志文件(RDP_LOG_DIR 目录),日志文件名按当前日期+时间自动命名
|
||||
// (如 rdp_20240826_153000.log,每次初始化一个文件);Destroy() 时关闭日志文件;
|
||||
// 2) 原 RDP_LOG_ENABLE 布尔开关已移除:日志级别改由 spdlog 的 SPDLOG_ACTIVE_LEVEL
|
||||
// 在编译期控制,由 CMake 选项 RDP_LOG_LEVEL(AUTO/TRACE/DEBUG/INFO/WARN/ERROR/
|
||||
// CRITICAL/OFF)映射;AUTO 时 Debug 构建 = TRACE、其余构建 = INFO,OFF 表示
|
||||
// 编译期关闭全部 RDP_LOG_* 日志。低于该级别的日志实参不求值。详见 README 10.4。
|
||||
|
||||
//日志文件输出目录(相对当前工作目录的路径,目录不存在时自动创建)
|
||||
#define RDP_LOG_DIR ".\\rdp_logs\\"
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
#include "rdp_log.h"
|
||||
#include "parameters.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <time.h>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <spdlog/sinks/stdout_sinks.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
//日志模块内部状态:日志文件流 + 重定向前 std::cout 的原始缓冲区
|
||||
//日志行格式:与旧版 [时间戳][文件:行号] 风格一致,另加 spdlog 级别
|
||||
const char *const kPattern = "[%Y-%m-%d %H:%M:%S.%e] [%l] [%s:%#] %v";
|
||||
|
||||
//日志模块内部状态:默认 logger(标准输出 + 日志文件)与当前日志文件路径
|
||||
struct RdpLogState
|
||||
{
|
||||
std::ofstream file; //日志文件输出流
|
||||
std::streambuf *original_buf; //重定向前 std::cout 的原始缓冲区
|
||||
bool enabled; //是否已成功重定向到日志文件
|
||||
std::shared_ptr<spdlog::logger> logger; //默认 logger(含标准输出 sink,成功时另含文件 sink)
|
||||
std::string log_path; //当前日志文件全路径(降级为仅标准输出时为空)
|
||||
bool initialized; //是否已初始化(含文件创建失败时的降级初始化)
|
||||
|
||||
RdpLogState() : original_buf(0), enabled(false) {}
|
||||
|
||||
~RdpLogState()
|
||||
{
|
||||
//进程退出兜底:若宿主进程未调用 Data_Process_Factory::Destroy(),
|
||||
//此处恢复 std::cout,避免其仍指向即将析构的日志文件流缓冲区。
|
||||
if (enabled && original_buf)
|
||||
{
|
||||
std::cout.rdbuf(original_buf);
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
RdpLogState() : initialized(false) {}
|
||||
};
|
||||
|
||||
RdpLogState &State()
|
||||
@@ -35,36 +33,78 @@ namespace
|
||||
return s;
|
||||
}
|
||||
|
||||
//当前本地时间字符串,格式 "YYYY-MM-DD HH:MM:SS"
|
||||
std::string CurrentTime()
|
||||
//创建日志目录(目录已存在时 _mkdir 返回 EEXIST,忽略;逻辑与原 rdp_log/rdp_record 一致)
|
||||
void EnsureDir(const std::string &dir_with_separator)
|
||||
{
|
||||
char buf[32] = {0};
|
||||
time_t now = time(NULL);
|
||||
std::string dir = dir_with_separator;
|
||||
while (dir.size() > 0 && (dir[dir.size() - 1] == '\\' || dir[dir.size() - 1] == '/'))
|
||||
{
|
||||
dir.erase(dir.size() - 1);
|
||||
}
|
||||
if (dir.size() > 0)
|
||||
{
|
||||
_mkdir(dir.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//当前本地时间字符串,格式 "YYYYMMDD_HHMMSS"
|
||||
bool TimeStamp(char *buf, size_t size)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm local;
|
||||
if (localtime_s(&local, &now) != 0)
|
||||
{
|
||||
return std::string();
|
||||
return false;
|
||||
}
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &local);
|
||||
return std::string(buf);
|
||||
return strftime(buf, size, "%Y%m%d_%H%M%S", &local) != 0;
|
||||
}
|
||||
|
||||
//提取纯文件名(去掉路径前缀),日志前缀中只显示 文件名:行号
|
||||
const char *FileName(const char *path)
|
||||
//生成日志文件路径:RDP_LOG_DIR + rdp_YYYYMMDD_HHMMSS.log;
|
||||
//同一秒内文件已存在(Destroy→GetB 重连、同目录多进程启动)时追加 _1~_999 后缀,不复用同一文件
|
||||
bool MakeLogPath(std::string *path)
|
||||
{
|
||||
if (path == 0)
|
||||
char stamp[32] = {0};
|
||||
if (!TimeStamp(stamp, sizeof(stamp)))
|
||||
{
|
||||
return "";
|
||||
return false;
|
||||
}
|
||||
const char *base = path;
|
||||
for (const char *p = path; *p != '\0'; ++p)
|
||||
const std::string base = std::string(RDP_LOG_DIR) + "rdp_" + stamp;
|
||||
for (int suffix = 0; suffix < 1000; ++suffix)
|
||||
{
|
||||
if (*p == '\\' || *p == '/')
|
||||
std::string candidate = base;
|
||||
if (suffix > 0)
|
||||
{
|
||||
base = p + 1;
|
||||
candidate += "_" + std::to_string(suffix);
|
||||
}
|
||||
candidate += ".log";
|
||||
if (_access(candidate.c_str(), 0) != 0)
|
||||
{
|
||||
*path = candidate;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return base;
|
||||
return false;
|
||||
}
|
||||
|
||||
//初始化 logger:统一日志格式,运行期级别放开到 trace(实际输出级别由编译期
|
||||
//SPDLOG_ACTIVE_LEVEL 过滤),所有级别逐条 flush(日志量小,且调试场景要求异常退出也尽量不丢日志)
|
||||
void ConfigureLogger(const std::shared_ptr<spdlog::logger> &logger)
|
||||
{
|
||||
logger->set_pattern(kPattern);
|
||||
logger->set_level(spdlog::level::trace);
|
||||
logger->flush_on(spdlog::level::trace);
|
||||
spdlog::set_default_logger(logger);
|
||||
}
|
||||
|
||||
//仅标准输出 sink 的降级 logger(日志文件创建失败时使用)
|
||||
std::shared_ptr<spdlog::logger> MakeStdoutLogger()
|
||||
{
|
||||
std::vector<spdlog::sink_ptr> sinks;
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
|
||||
std::shared_ptr<spdlog::logger> logger =
|
||||
std::make_shared<spdlog::logger>("rdp", sinks.begin(), sinks.end());
|
||||
ConfigureLogger(logger);
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,82 +113,84 @@ namespace rdp_log
|
||||
bool Init()
|
||||
{
|
||||
RdpLogState &st = State();
|
||||
if (st.enabled)
|
||||
if (st.initialized)
|
||||
{
|
||||
return true; //已经重定向,避免重复初始化
|
||||
return true; //已经初始化,避免重复创建日志文件
|
||||
}
|
||||
|
||||
#ifdef RDP_LOG_ENABLE
|
||||
//创建日志目录(目录已存在时 _mkdir 返回 EEXIST,忽略)
|
||||
std::string log_dir = RDP_LOG_DIR;
|
||||
while (log_dir.size() > 0 &&
|
||||
(log_dir[log_dir.size() - 1] == '\\' || log_dir[log_dir.size() - 1] == '/'))
|
||||
{
|
||||
log_dir.erase(log_dir.size() - 1);
|
||||
}
|
||||
if (log_dir.size() > 0)
|
||||
{
|
||||
_mkdir(log_dir.c_str());
|
||||
}
|
||||
|
||||
//按当前日期+时间生成日志文件名:rdp_YYYYMMDD_HHMMSS.log
|
||||
char time_buf[32] = {0};
|
||||
time_t now = time(NULL);
|
||||
struct tm local;
|
||||
if (localtime_s(&local, &now) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
strftime(time_buf, sizeof(time_buf), "%Y%m%d_%H%M%S", &local);
|
||||
|
||||
std::string log_path = RDP_LOG_DIR;
|
||||
log_path += "rdp_";
|
||||
log_path += time_buf;
|
||||
log_path += ".log";
|
||||
|
||||
st.file.open(log_path.c_str(), std::ios::out | std::ios::trunc);
|
||||
if (!st.file.is_open())
|
||||
{
|
||||
//日志文件打开失败(目录不可写等):保持控制台输出,不做重定向
|
||||
std::cout << "[rdp_log] cannot open log file: " << log_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//用 rdbuf() 将 std::cout 的流缓冲区替换为日志文件输出流
|
||||
st.original_buf = std::cout.rdbuf();
|
||||
std::cout.rdbuf(st.file.rdbuf());
|
||||
st.enabled = true;
|
||||
|
||||
//重定向成功后写入起始标记(该行已写入日志文件)
|
||||
std::cout << prefix(__FILE__, __LINE__)
|
||||
<< "rdp_log enabled, log file: " << log_path << std::endl;
|
||||
return true;
|
||||
#else
|
||||
//日志开关关闭:不重定向,日志仍输出到标准输出
|
||||
#if SPDLOG_ACTIVE_LEVEL > SPDLOG_LEVEL_CRITICAL
|
||||
//编译期关闭日志(RDP_LOG_LEVEL=OFF):不初始化 logger、不创建日志文件
|
||||
return false;
|
||||
#else
|
||||
try
|
||||
{
|
||||
EnsureDir(RDP_LOG_DIR);
|
||||
|
||||
std::string log_path;
|
||||
if (!MakeLogPath(&log_path))
|
||||
{
|
||||
throw spdlog::spdlog_ex("no usable log file name in RDP_LOG_DIR");
|
||||
}
|
||||
|
||||
std::vector<spdlog::sink_ptr> sinks;
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
|
||||
//truncate=false:日志文件名已保证不存在(极端并发下万一被抢占则追加而非覆盖已有内容)
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(log_path, false));
|
||||
|
||||
std::shared_ptr<spdlog::logger> logger =
|
||||
std::make_shared<spdlog::logger>("rdp", sinks.begin(), sinks.end());
|
||||
ConfigureLogger(logger);
|
||||
|
||||
//spdlog 内部错误(如日志文件写失败)打到标准错误,不影响雷达数据处理
|
||||
spdlog::set_error_handler([](const std::string &msg) {
|
||||
std::fprintf(stderr, "[rdp_log] spdlog error: %s\n", msg.c_str());
|
||||
});
|
||||
|
||||
st.logger = logger;
|
||||
st.log_path = log_path;
|
||||
st.initialized = true;
|
||||
|
||||
RDP_LOG_INFO("rdp_log enabled, log file: {}", log_path);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
//日志文件创建失败(目录不可写等):降级为仅标准输出,不中断雷达数据处理
|
||||
try
|
||||
{
|
||||
st.logger = MakeStdoutLogger();
|
||||
st.log_path.clear();
|
||||
st.initialized = true;
|
||||
std::fprintf(stderr, "[rdp_log] cannot create log file, fallback to stdout only: %s\n",
|
||||
e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::fprintf(stderr, "[rdp_log] logger init failed\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
RdpLogState &st = State();
|
||||
if (!st.enabled)
|
||||
if (!st.initialized || !st.logger)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//写入结束标记后刷新、恢复 std::cout 并关闭日志文件
|
||||
std::cout << prefix(__FILE__, __LINE__) << "rdp_log shutdown" << std::endl;
|
||||
st.file.flush();
|
||||
std::cout.rdbuf(st.original_buf);
|
||||
st.enabled = false;
|
||||
st.file.close();
|
||||
RDP_LOG_INFO("rdp_log shutdown");
|
||||
//flush 并释放默认 logger(随之关闭日志文件)
|
||||
spdlog::shutdown();
|
||||
st.logger.reset();
|
||||
st.log_path.clear();
|
||||
st.initialized = false;
|
||||
}
|
||||
|
||||
std::string prefix(const char *file, int line)
|
||||
std::string log_file_path()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "[" << CurrentTime() << "][" << FileName(file) << ":" << line << "] ";
|
||||
return oss.str();
|
||||
return State().log_path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,26 +2,46 @@
|
||||
#define RDP_LOG_H
|
||||
#pragma once
|
||||
/*************************************日志输出模块*******************************************/
|
||||
// 功能:
|
||||
// 1) rdp_log::Init():按 parameters.h 中 RDP_LOG_ENABLE 宏开关决定是否将 std::cout
|
||||
// 重定向到日志文件(RDP_LOG_DIR 目录,文件名按当前日期+时间自动生成)。
|
||||
// 开关关闭(注释掉 RDP_LOG_ENABLE)时不做重定向,日志仍输出到标准输出。
|
||||
// 2) rdp_log::Shutdown():恢复 std::cout 原始缓冲区(回到控制台)并关闭日志文件。
|
||||
// 3) RDP_LOG 宏:日志输出宏,在每条日志前自动附加 [时间戳][代码文件:行号] 信息,
|
||||
// 随后输出到 std::cout(若开关开启则随 cout 一并写入日志文件)。
|
||||
// 用法示例:
|
||||
// RDP_LOG << "目标批号:" << track_index << std::endl;
|
||||
#include <iostream>
|
||||
// 基于 spdlog v1.17.0(third_party/spdlog,来源/版本见该目录 UPSTREAM.md,以静态库目标
|
||||
// spdlog 链接,见 CMakeLists.txt):
|
||||
// 1) rdp_log::Init():创建 RDP_LOG_DIR 下按「日期+时间」命名的日志文件(每次初始化一个
|
||||
// 文件;同一秒内文件已存在时追加 _1~_999 后缀),默认 logger 同时输出到 标准输出 与
|
||||
// 日志文件 两个 sink。由 Data_Process_Factory::GetB() 调用;
|
||||
// 2) rdp_log::Shutdown():打印结束标记、flush 并释放 logger(关闭日志文件),由
|
||||
// Data_Process_Factory::Destroy() 调用;
|
||||
// 3) 日志宏 RDP_LOG_TRACE / RDP_LOG_DEBUG / RDP_LOG_INFO / RDP_LOG_WARN /
|
||||
// RDP_LOG_ERROR / RDP_LOG_CRITICAL:级别与 spdlog 一致(RDP_LOG_ERR 为
|
||||
// RDP_LOG_ERROR 的别名),支持 fmt 风格的格式化,用法示例:
|
||||
// RDP_LOG_INFO("目标批号:{},时间:{}", track_index, cpi_time);
|
||||
// 低于 SPDLOG_ACTIVE_LEVEL 的日志调用在编译期被剔除(实参不求值),该级别由 CMake
|
||||
// 选项 RDP_LOG_LEVEL 控制(见 CMakeLists.txt 与 README 10.4),即原 RDP_LOG_ENABLE
|
||||
// 开关改由 SPDLOG_ACTIVE_LEVEL 在编译期控制日志级别(OFF = 编译期关闭全部日志)。
|
||||
//
|
||||
// 日志文件路径/名称与旧实现保持一致:RDP_LOG_DIR(.\rdp_logs\)+ rdp_YYYYMMDD_HHMMSS.log。
|
||||
// 日志行格式:"[YYYY-MM-DD HH:MM:SS.mmm] [级别] [文件名:行号] 内容",级别为 spdlog 默认
|
||||
// 名称 trace/debug/info/warning/error/critical。
|
||||
#include <string>
|
||||
|
||||
// 第三方头文件告警隔离:spdlog 按 third_party 依赖处理(见 README 4.5)
|
||||
#pragma warning(push, 0)
|
||||
#include <spdlog/spdlog.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
namespace rdp_log
|
||||
{
|
||||
bool Init(); //初始化日志输出(由 Data_Process_Factory::GetB() 调用)
|
||||
void Shutdown(); //恢复 std::cout 并关闭日志文件(由 Data_Process_Factory::Destroy() 调用)
|
||||
std::string prefix(const char *file, int line); //生成 "[时间戳][文件名:行号] " 前缀字符串
|
||||
bool Init(); //初始化日志输出(标准输出 + 日志文件;由 GetB() 调用)
|
||||
void Shutdown(); //flush、释放 logger 并关闭日志文件(由 Destroy() 调用)
|
||||
std::string log_file_path(); //当前日志文件全路径(未初始化或文件创建失败时为空串)
|
||||
}
|
||||
|
||||
//日志输出宏:自动附加 时间戳、代码文件、代码行号 后输出到标准输出(std::cout)
|
||||
#define RDP_LOG std::cout << rdp_log::prefix(__FILE__, __LINE__)
|
||||
//日志级别宏(spdlog 编译期级别过滤:低于 SPDLOG_ACTIVE_LEVEL 的调用被剔除、实参不求值)
|
||||
#define RDP_LOG_TRACE(...) SPDLOG_TRACE(__VA_ARGS__)
|
||||
#define RDP_LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__)
|
||||
#define RDP_LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__)
|
||||
#define RDP_LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__)
|
||||
#define RDP_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__)
|
||||
#define RDP_LOG_CRITICAL(...) SPDLOG_CRITICAL(__VA_ARGS__)
|
||||
//兼容别名:需求中的级别名 err 对应 spdlog::level::err,宏名同时提供 RDP_LOG_ERR
|
||||
#define RDP_LOG_ERR(...) RDP_LOG_ERROR(__VA_ARGS__)
|
||||
|
||||
#endif // RDP_LOG_H
|
||||
|
||||
@@ -150,21 +150,21 @@ namespace
|
||||
//写入失败提示
|
||||
void ReportError(Record_State& st, const char* what, const std::string& detail)
|
||||
{
|
||||
RDP_LOG << "[rdp_record] " << what << " failed (" << detail << "): "
|
||||
<< st.db.get_last_error() << std::endl;
|
||||
RDP_LOG_ERROR("[rdp_record] {} failed ({}): {}", what, detail, st.db.get_last_error());
|
||||
}
|
||||
|
||||
void LogStats(Record_State& st, const char* tag)
|
||||
{
|
||||
RDP_LOG << "[rdp_record] stats(" << tag << "): enqueued_rows="
|
||||
<< st.counters.enqueued_rows.load()
|
||||
<< ", written_rows=" << st.counters.written_rows.load()
|
||||
<< ", dropped_rows=" << st.counters.dropped_rows.load()
|
||||
<< ", transactions=" << st.counters.transactions.load()
|
||||
<< ", write_errors=" << st.counters.write_errors.load()
|
||||
<< ", queue_peak_bytes=" << st.counters.queue_peak_bytes.load()
|
||||
<< ", queue_peak_rows=" << st.counters.queue_peak_rows.load()
|
||||
<< std::endl;
|
||||
RDP_LOG_INFO("[rdp_record] stats({}): enqueued_rows={}, written_rows={}, dropped_rows={}, "
|
||||
"transactions={}, write_errors={}, queue_peak_bytes={}, queue_peak_rows={}",
|
||||
tag,
|
||||
st.counters.enqueued_rows.load(),
|
||||
st.counters.written_rows.load(),
|
||||
st.counters.dropped_rows.load(),
|
||||
st.counters.transactions.load(),
|
||||
st.counters.write_errors.load(),
|
||||
st.counters.queue_peak_bytes.load(),
|
||||
st.counters.queue_peak_rows.load());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -253,21 +253,21 @@ namespace
|
||||
//因此用 query_s<std::tuple<...>> 消费返回行。
|
||||
auto rows = st.db.query_s<std::tuple<std::string>>("PRAGMA journal_mode=WAL;");
|
||||
std::string mode = rows.empty() ? std::string("<none>") : std::get<0>(rows[0]);
|
||||
RDP_LOG << "[rdp_record] journal_mode=" << mode << std::endl;
|
||||
RDP_LOG_INFO("[rdp_record] journal_mode={}", mode);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
RDP_LOG << "[rdp_record] set journal_mode=WAL failed, fallback to default journal" << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] set journal_mode=WAL failed, fallback to default journal");
|
||||
}
|
||||
#endif
|
||||
if (!st.db.execute("PRAGMA synchronous=OFF;"))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] set synchronous=OFF failed" << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] set synchronous=OFF failed");
|
||||
}
|
||||
const std::string cache = "PRAGMA cache_size=-" + std::to_string(RDP_RECORD_SQLITE_CACHE_KB) + ";";
|
||||
if (!st.db.execute(cache))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] set cache_size failed" << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] set cache_size failed");
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -277,7 +277,7 @@ namespace
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
RDP_LOG << "[rdp_record] set busy_timeout failed" << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] set busy_timeout failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,14 +324,14 @@ namespace
|
||||
if (st.db.execute("DROP TABLE \"" + table + "\";") &&
|
||||
st.db.execute(stripped))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] table " << table << " created without AUTOINCREMENT" << std::endl;
|
||||
RDP_LOG_INFO("[rdp_record] table {} created without AUTOINCREMENT", table);
|
||||
return true;
|
||||
}
|
||||
|
||||
//回退:若重建失败(极端情况),尽量恢复一张可用表,保证记录功能继续
|
||||
if (st.db.create_datatable<T>(::ormpp_auto_key{"id"}))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] warning: keep AUTOINCREMENT for " << table << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] warning: keep AUTOINCREMENT for {}", table);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -391,7 +391,7 @@ namespace
|
||||
if (errors >= RDP_RECORD_MAX_CONSECUTIVE_ERRORS)
|
||||
{
|
||||
st.failed.store(true);
|
||||
RDP_LOG << "[rdp_record] too many consecutive write errors, recording stopped" << std::endl;
|
||||
RDP_LOG_ERROR("[rdp_record] too many consecutive write errors, recording stopped");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -465,7 +465,7 @@ namespace
|
||||
}
|
||||
if ((total_dropped / interval) != ((total_dropped - newly_dropped) / interval))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] queue full, dropped rows total=" << total_dropped << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] queue full, dropped rows total={}", total_dropped);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,8 +540,7 @@ namespace
|
||||
if (rows > 0)
|
||||
{
|
||||
const std::uint64_t total = st.counters.dropped_rows.fetch_add(rows) + rows;
|
||||
RDP_LOG << "[rdp_record] writer stopped, dropped queued rows=" << rows
|
||||
<< ", total dropped=" << total << std::endl;
|
||||
RDP_LOG_INFO("[rdp_record] writer stopped, dropped queued rows={}, total dropped={}", rows, total);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +627,7 @@ namespace
|
||||
{
|
||||
//写线程内任何异常都不能抛出 DLL 边界;记录失败即降级
|
||||
st.failed.store(true);
|
||||
RDP_LOG << "[rdp_record] writer thread exception, recording stopped" << std::endl;
|
||||
RDP_LOG_ERROR("[rdp_record] writer thread exception, recording stopped");
|
||||
DropQueued(st);
|
||||
}
|
||||
}
|
||||
@@ -694,7 +693,7 @@ namespace rdp_record
|
||||
char stamp[32] = {0};
|
||||
if (!TimeStamp(stamp, sizeof(stamp)))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] cannot get local time, recording disabled" << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] cannot get local time, recording disabled");
|
||||
st.failed = true;
|
||||
return false;
|
||||
}
|
||||
@@ -720,7 +719,7 @@ namespace rdp_record
|
||||
|
||||
if (!st.db.connect(st.path))
|
||||
{
|
||||
RDP_LOG << "[rdp_record] cannot open database: " << st.path << std::endl;
|
||||
RDP_LOG_WARN("[rdp_record] cannot open database: {}", st.path);
|
||||
st.failed = true;
|
||||
return false;
|
||||
}
|
||||
@@ -731,18 +730,17 @@ namespace rdp_record
|
||||
st.writer = std::thread(WriterLoop, std::ref(st));
|
||||
st.ready = true;
|
||||
|
||||
RDP_LOG << "[rdp_record] enabled, database: " << st.path
|
||||
<< " (async writer, write_batch_rows=" << RDP_RECORD_WRITE_BATCH_ROWS
|
||||
<< ", queue_cap_bytes=" << RDP_RECORD_QUEUE_CAP_BYTES << ")" << std::endl;
|
||||
RDP_LOG_INFO("[rdp_record] enabled, database: {} (async writer, write_batch_rows={}, queue_cap_bytes={})",
|
||||
st.path, RDP_RECORD_WRITE_BATCH_ROWS, RDP_RECORD_QUEUE_CAP_BYTES);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
RDP_LOG << "[rdp_record] init exception: " << e.what() << std::endl;
|
||||
RDP_LOG_ERROR("[rdp_record] init exception: {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
RDP_LOG << "[rdp_record] init exception" << std::endl;
|
||||
RDP_LOG_ERROR("[rdp_record] init exception");
|
||||
}
|
||||
|
||||
st.failed = true;
|
||||
@@ -796,7 +794,7 @@ namespace rdp_record
|
||||
{
|
||||
}
|
||||
|
||||
RDP_LOG << "[rdp_record] shutdown, database: " << st.path << std::endl;
|
||||
RDP_LOG_INFO("[rdp_record] shutdown, database: {}", st.path);
|
||||
st.ready = false;
|
||||
//保留状态对象(连接已断开、写线程已退出):下次 Init() 检测到 !ready && !failed 时复位并重新建库。
|
||||
//不在 Shutdown 内直接释放,避免宿主在 Destroy 的同时仍有记录调用时出现悬空指针(防御性处理)。
|
||||
|
||||
@@ -194,7 +194,7 @@ struct RDP_parameter
|
||||
{
|
||||
// ******************* 雷达工作参数 ************************//
|
||||
int radar_work_mode; //工作模式
|
||||
int scan_mode; //扫描模式 0=相扫模式 1=机扫模式(决定判圈逻辑,替代原编译期 PHASE_SCANNING/MECHANICAL_SCANNING 分支)
|
||||
int scan_mode; //扫描模式 0=相扫模式 1=机扫模式
|
||||
float freq_0_GHz; //频点0频率
|
||||
float radar_height; //雷达平台高度 (m)
|
||||
float radar_system_delay; //系统延迟 (s)
|
||||
|
||||
@@ -305,5 +305,5 @@ void TAS_Ctrl::tas_beam_output(std::vector<Trust_Track> *trust_track
|
||||
//跟踪波束开关开启
|
||||
Tracking_beam->open_flag=1;
|
||||
|
||||
//RDP_LOG << "TAS <" << (*trust_track)[earliest_track_idx].Track_Index << "> output: range: " <<Tracking_beam->Range << "azi: " <<Tracking_beam->Azi <<"pit: " <<Tracking_beam->Elev << std::endl;
|
||||
//RDP_LOG_DEBUG("TAS <{}> output: range: {} azi: {} pit: {}", (*trust_track)[earliest_track_idx].Track_Index, Tracking_beam->Range, Tracking_beam->Azi, Tracking_beam->Elev);
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
double freq_ind = point_process[loop_of_point].freq_index;
|
||||
double delta_T = (point_process[loop_of_point].CPI_time - T_track)/1000.0;
|
||||
if (delta_T <= 0){
|
||||
RDP_LOG << "Warning: delta_T <= 0, skipping point association for point index " << point_process[loop_of_point].CPI_time << " " << T_track << std::endl;
|
||||
RDP_LOG_WARN("Warning: delta_T <= 0, skipping point association for point index {} {}", point_process[loop_of_point].CPI_time, T_track);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
//有关联 滤波
|
||||
if (associated_info.size()>0)
|
||||
{
|
||||
//RDP_LOG << "associated point for track index " << tas_track_idx << std::endl;
|
||||
//RDP_LOG_DEBUG("associated point for track index {}", tas_track_idx);
|
||||
// std::cout << "TAS asoooooo222" ;
|
||||
|
||||
//找最近点
|
||||
@@ -527,7 +527,7 @@ void Track_Asso_Tas::model_filter( std::vector<Trust_Track> *t
|
||||
//未关联上,航迹外推
|
||||
else
|
||||
{
|
||||
//RDP_LOG << "unassociated point for track index " << tas_track_idx << std::endl;
|
||||
//RDP_LOG_DEBUG("unassociated point for track index {}", tas_track_idx);
|
||||
for(size_t i=0;i<trust_track->size();i++){
|
||||
if((*trust_track)[i].Track_Index == tas_track_idx)
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ void Track_Die_Tas::track_die_process_tas( std::vector <Trust_Track> *trust_trac
|
||||
|
||||
if(die_flag)
|
||||
{
|
||||
// RDP_LOG << "remove tas target :" << (*Iter).Track_Index << std::endl;
|
||||
// RDP_LOG_DEBUG("remove tas target :{}", (*Iter).Track_Index);
|
||||
//输出消亡信息
|
||||
*Track_die_num_Output=*Track_die_num_Output+1;
|
||||
Track_die_Index_Output[*Track_die_num_Output-1]=(*Iter).Track_Index;
|
||||
|
||||
Reference in New Issue
Block a user