Browse Source

2.3.1| 调整默认logger配置文件

master
zhaohe 1 month ago
parent
commit
2dd8c83eb6
  1. 33
      appdep/iflytop/core/spdlogfactory/logger_factory.cpp
  2. 44
      appdep/iflytop/core/spdlogfactory/logger_factory.hpp
  3. 8
      appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp
  4. 2
      appsrc/appconfig/basic/zappversion.hpp
  5. 4
      appsrc/baseservice/db/setting_db_dao.cpp
  6. 64
      appsrc/main.cpp

33
appdep/iflytop/core/spdlogfactory/logger_factory.cpp

@ -603,6 +603,26 @@ class MonitoringSpdLoggerConfigTask {
}
~MonitoringSpdLoggerConfigTask() { wthread->join(); }
};
void SpdLoggerFactory::initialize(string configContent) {
if (!initializeLogger) {
string configFilePath = getConfigFilePath();
if (!configFilePath.empty() && exist(configFilePath)) {
parseSphLogConfig(configFilePath);
} else {
spdlog::warn("can't find logger config file use default config {}", configFilePath);
// 写字符串default_config到文件中configFilePath
ofstream outfile(configFilePath);
if(configContent.empty()) {
outfile << default_config;
} else {
outfile << configContent;
}
outfile.close();
parseSphLogConfig(configFilePath);
}
initializeLogger = true;
}
}
shared_ptr<logger> SpdLoggerFactory::createLogger(string loggerName) {
lock_guard<mutex> lock_gu(createLogger_lock);
@ -624,18 +644,7 @@ shared_ptr<logger> SpdLoggerFactory::createLogger(string loggerName) {
}
if (!initializeLogger) {
string configFilePath = getConfigFilePath();
if (!configFilePath.empty() && exist(configFilePath)) {
parseSphLogConfig(configFilePath);
} else {
spdlog::warn("can't find logger config file use default config {}", configFilePath);
// 写字符串default_config到文件中configFilePath
ofstream outfile(configFilePath);
outfile << default_config;
outfile.close();
parseSphLogConfig(configFilePath);
}
initializeLogger = true;
initialize("");
}
logger_t ret_logger = get(loggerName);

44
appdep/iflytop/core/spdlogfactory/logger_factory.hpp

@ -3,8 +3,6 @@
//
#pragma once
#include "spdlog/spdlog.h"
#include <fstream>
#include <iostream>
#include <list>
@ -14,6 +12,7 @@
#include <sstream>
#include <string>
#include <vector>
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
@ -26,36 +25,33 @@ using namespace std;
using namespace spdlog;
typedef shared_ptr<logger> logger_t;
#define ENABLE_LOGGER(loggerName) \
public: \
iflytop::core::logger_t logger = \
iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName); \
\
#define ENABLE_LOGGER(loggerName) \
public: \
iflytop::core::logger_t logger = iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName); \
\
private:
#define CREATE_LOGGER(loggerName) \
iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName)
#define CREATE_LOGGER(loggerName) iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName)
#define GET_LOGGER(loggerName) \
iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName)
#define GET_LOGGER(loggerName) iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName)
#define ENABLE_LOGGER_STATIC(loggerName) \
static iflytop::core::logger_t logger = \
iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName);
#define ENABLE_LOGGER_STATIC(loggerName) static iflytop::core::logger_t logger = iflytop::core::SpdLoggerFactory::Instance().createLogger(#loggerName);
class SpdLoggerFactory {
SpdLoggerFactory(){};
std::mutex createLogger_lock;
atomic_bool initializeLogger = {false};
set<string> s_loggerNames;
public:
static SpdLoggerFactory& Instance() {
static SpdLoggerFactory factory;
return factory;
SpdLoggerFactory() {};
std::mutex createLogger_lock;
atomic_bool initializeLogger = {false};
set<string> s_loggerNames;
public:
static SpdLoggerFactory& Instance() {
static SpdLoggerFactory factory;
return factory;
}
shared_ptr<logger> createLogger(string loggerName);
set<string> loggerNames();
set<string> loggerNames();
void initialize(string configContent);
private:
void parseSphLogConfig(string path);

8
appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp

@ -24,7 +24,7 @@ void ZSCanProtocolCom::initialize() {
tdcan_frame_t *rxframe = (tdcan_frame_t *)data;
if (rxframe->ptype == kreceipt || rxframe->ptype == kerror_receipt) {
logger->debug("<--- rx receipt index:{} {}({})", rxframe->index, rxframe->ptype, hexStr, len);
logger->trace("<--- rx receipt index:{} {}({})", rxframe->index, rxframe->ptype, hexStr, len);
if (rxframe->index == m_rxReceiptContext.waittingIndex) {
lock_guard<mutex> lock(m_rxReceiptContext_lock);
@ -37,10 +37,10 @@ void ZSCanProtocolCom::initialize() {
} else if (rxframe->ptype == kcmd) {
logger->warn("<--- rx cmd ? {}({})", rxframe->ptype, hexStr, len);
} else if (rxframe->ptype == kreport) {
logger->debug("<--- rx report ptype:{} {}({})", rxframe->ptype, hexStr, len);
logger->trace("<--- rx report ptype:{} {}({})", rxframe->ptype, hexStr, len);
callOnReport(rxframe->from, (uint8_t *)rxframe, len);
} else {
logger->debug("<--- rx unkown ptype:{}", rxframe->ptype);
logger->trace("<--- rx unkown ptype:{}", rxframe->ptype);
}
});
}
@ -76,7 +76,7 @@ shared_ptr<Receipt> ZSCanProtocolCom::base_callcmd(int32_t to, int32_t cmdid, ui
string hexStr = StringUtils().bytesToString((uint8_t *)packet, totallen);
m_zexcan_socket->sendPacket((uint8_t *)packet, totallen);
logger->debug("---> tx cmd index:{} {}({})", packet->index, hexStr, totallen);
logger->trace("---> tx cmd index:{} {}({})", packet->index, hexStr, totallen);
if (to == 0xff) return nullptr; // 广播包没有回执
bool rxreceipt = false;

2
appsrc/appconfig/basic/zappversion.hpp

@ -1,3 +1,3 @@
#pragma once
#define VERSION "2.3.0"
#define VERSION "2.3.1"
#define PROJECT_NAME "TRANSMIT_DM"

4
appsrc/baseservice/db/setting_db_dao.cpp

@ -76,7 +76,7 @@ static Setting settingInitTable[] = {
INT_SETTING(SettingId::kpre_heat_time_s, "预热时间", "120", "0", "1200", /* */ true, true, true, true),
INT_SETTING(SettingId::kstoped_humi, "消毒停止相对湿度", "85", "0", "100", /* */ true, true, true, true),
INT_SETTING(SettingId::kcontinued_humi, "消毒继续相对湿度", "60", "0", "100", /* */ true, true, true, true),
INT_SETTING(SettingId::kproportional_valve_default_value, "正负压默认开合比例", "10", "0", "100", /* */ true, true, true, true),
INT_SETTING(SettingId::kproportional_valve_default_value, "正负压默认开合比例", "10", "0", "100", /* */ false, false, false, false), // delete in the future....
INT_SETTING(SettingId::krecord_period_min, "消毒日志记录间隔(Min)", "2", "1", "30", /* */ true, true, false, false),
INT_SETTING(SettingId::krecord_printer_period_min, "消毒日志打印间隔(Min)", "5", "1", "30", /* */ true, true, false, false),
ENUM_SETTING(SettingId::kloglevel, "消毒等级", "6", vector<string>({"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}), //
@ -102,7 +102,7 @@ list<shared_ptr<Setting>> SettingDBDao::getRealtimeSetting() {
void SettingDBDao::initialize() { //
try {
mkdir("db", 0755);
mkdir("db", 0755);
keyvaldb.initialize("db/setting.db", "setting");
string version = keyvaldb.get("version");
if (version != DB_VERSION) {

64
appsrc/main.cpp

@ -61,10 +61,74 @@ void Main::run(int argc, char *argv[]) {
thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); }));
while (true) sleep(1000);
}
json build_default_logger_cfg() {
json config;
json infologger;
infologger["name"] = "infologger";
infologger["type"] = "rotating_file_sink_mt";
infologger["filename"] = "logs/infolog.log";
infologger["max_file_size"] = 10485760; // 10MB
infologger["max_files"] = 30;
infologger["rotate_on_open"] = false;
infologger["level"] = 2; // info level
config.push_back(infologger);
json debuglogger;
debuglogger["name"] = "debuglogger";
debuglogger["type"] = "rotating_file_sink_mt";
debuglogger["filename"] = "logs/debuglog.log";
debuglogger["max_file_size"] = 10485760; // 10MB
debuglogger["max_files"] = 30;
debuglogger["rotate_on_open"] = false;
debuglogger["level"] = 1; // info level
config.push_back(debuglogger);
json terminal;
terminal["name"] = "terminal";
terminal["type"] = "stdout_color_sink_mt";
config.push_back(terminal);
json h2o2SensorDataMgr;
h2o2SensorDataMgr["name"] = "H2O2SensorDataMgr";
h2o2SensorDataMgr["level"] = 1; // info level
config.push_back(h2o2SensorDataMgr);
json zsCanProtocolCom;
zsCanProtocolCom["name"] = "ZSCanProtocolCom";
zsCanProtocolCom["level"] = 1; // info level
config.push_back(zsCanProtocolCom);
json frontMsgProcesser;
frontMsgProcesser["name"] = "FrontMsgProcesser";
frontMsgProcesser["level"] = 1; // info level
config.push_back(frontMsgProcesser);
json iflytopFrontEndService;
iflytopFrontEndService["name"] = "IflytopFrontEndService";
iflytopFrontEndService["level"] = 1; // info level
config.push_back(iflytopFrontEndService);
json root;
root["name"] = "root";
root["type"] = "logger";
root["level"] = 2; // info level
root["sinks"] = json::array();
root["sinks"].push_back("terminal");
root["sinks"].push_back("infologger");
root["sinks"].push_back("debuglogger");
config.push_back(root);
return config;
}
int Main::main(int argc, char *argv[]) {
/**
* @brief
*/
SpdLoggerFactory::Instance().initialize(build_default_logger_cfg());
logger->info("system setup start.");
spdlog::flush_on(spdlog::level::debug);
logger->info("#");

Loading…
Cancel
Save