mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
feat.日志新增文件过大自动删除的功能
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
#include <filesystem>
|
||||
|
||||
#include "AsstAux.h"
|
||||
#include "Version.h"
|
||||
@@ -46,7 +47,22 @@ namespace asst {
|
||||
|
||||
private:
|
||||
Logger()
|
||||
: m_ofstream(asst::GetCurrentDir() + "asst.log", std::ios::out | std::ios::app)
|
||||
{
|
||||
check_filesize_and_remove();
|
||||
m_ofstream = std::ofstream(m_log_filename, std::ios::out | std::ios::app);
|
||||
log_init_info();
|
||||
}
|
||||
|
||||
void check_filesize_and_remove()
|
||||
{
|
||||
constexpr uintmax_t MaxLogSize = 4 * 1024 * 1024;
|
||||
uintmax_t log_size = std::filesystem::file_size(m_log_filename);
|
||||
if (log_size >= MaxLogSize) {
|
||||
const static std::string back_filename = asst::GetCurrentDir() + "asst.bak.log";
|
||||
std::filesystem::rename(m_log_filename, back_filename);
|
||||
}
|
||||
}
|
||||
void log_init_info()
|
||||
{
|
||||
log_trace("-----------------------------");
|
||||
log_trace("MeoAssistance Process Start");
|
||||
@@ -102,6 +118,7 @@ namespace asst {
|
||||
|
||||
std::mutex m_trace_mutex;
|
||||
std::ofstream m_ofstream;
|
||||
const std::string m_log_filename = asst::GetCurrentDir() + "asst.log";
|
||||
};
|
||||
|
||||
class LoggerAux {
|
||||
|
||||
@@ -19,7 +19,7 @@ bool TaskConfiger::set_param(const std::string& type, const std::string& param,
|
||||
}
|
||||
auto task_info_ptr = m_all_tasks_info[param];
|
||||
std::string action = value;
|
||||
std::transform(action.begin(), action.end(), action.begin(), std::tolower);
|
||||
std::transform(action.begin(), action.end(), action.begin(), ::tolower);
|
||||
if (action == "clickself") {
|
||||
task_info_ptr->action = ProcessTaskAction::ClickSelf;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ bool asst::TaskConfiger::parse(const json::value& json)
|
||||
{
|
||||
for (const auto& [name, task_json] : json.as_object()) {
|
||||
std::string algorithm_str = task_json.get("algorithm", "matchtemplate");
|
||||
std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), std::tolower);
|
||||
std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower);
|
||||
AlgorithmType algorithm = AlgorithmType::Invaild;
|
||||
if (algorithm_str == "matchtemplate") {
|
||||
algorithm = AlgorithmType::MatchTemplate;
|
||||
@@ -106,7 +106,7 @@ bool asst::TaskConfiger::parse(const json::value& json)
|
||||
task_info_ptr->algorithm = algorithm;
|
||||
task_info_ptr->name = name;
|
||||
std::string action = task_json.at("action").as_string();
|
||||
std::transform(action.begin(), action.end(), action.begin(), std::tolower);
|
||||
std::transform(action.begin(), action.end(), action.begin(), ::tolower);
|
||||
if (action == "clickself") {
|
||||
task_info_ptr->action = ProcessTaskAction::ClickSelf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user