mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-06 16:10:42 +08:00
Update log_cleaner.cpp
This commit is contained in:
@@ -1,18 +1,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
// 定义日志目录路径
|
// 定义日志目录路径
|
||||||
fs::path logDir = "logs";
|
fs::path logDir = "logs";
|
||||||
size_t deletedCount = 0;
|
size_t deletedCount = 0;
|
||||||
size_t errorCount = 0;
|
size_t errorCount = 0;
|
||||||
|
|
||||||
// 检查目录是否存在
|
// 检查目录是否存在
|
||||||
if (fs::exists(logDir) && fs::is_directory(logDir)) {
|
if (fs::exists(logDir) && fs::is_directory(logDir)) {
|
||||||
// 遍历并删除所有日志文件
|
// 遍历并删除所有日志文件
|
||||||
@@ -31,19 +27,15 @@ int main() {
|
|||||||
std::cout << "日志目录不存在,无需清理" << std::endl;
|
std::cout << "日志目录不存在,无需清理" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||||
|
|
||||||
std::cout << "日志清理完成: " << std::endl;
|
std::cout << "日志清理完成: " << std::endl;
|
||||||
std::cout << "删除文件数: " << deletedCount << std::endl;
|
std::cout << "删除文件数: " << deletedCount << std::endl;
|
||||||
std::cout << "错误数: " << errorCount << std::endl;
|
std::cout << "错误数: " << errorCount << std::endl;
|
||||||
std::cout << "耗时: " << duration.count() << " 毫秒" << std::endl;
|
std::cout << "耗时: " << duration.count() << " 毫秒" << std::endl;
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "发生错误: " << e.what() << std::endl;
|
std::cerr << "发生错误: " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user