From 63989e7910ddd40c5dae64022e80c07a3b598043 Mon Sep 17 00:00:00 2001 From: wxx <1321839169@qq.com> Date: 星期三, 30 十月 2024 15:06:24 +0800 Subject: [PATCH] Merge branch 'master' of ssh://115.28.86.8:29418/~admin/昆仑_1025 --- Client/李宵增/document/历史查询分析模块需求分析.docx | 0 Server/胡家明/document/网络socket搭建需求分析.docx | 0 昆仑项目文件/昆仑项目风险管理表.xlsx | 0 Server/马丽萍/code/log/.vscode/launch.json | 24 ++ Server/马渝杭/document/版本更新功能需求_server.docx | 0 Server/李转转/document/需求分析报告.docx | 0 Client/申烜/document/注册登录需求分析.docx | 0 Server/王琨元/document/数据库模块需求分析.docx | 0 Server/马丽萍/code/log/.vscode/c_cpp_properties.json | 18 + Server/王琨元/document/建表.docx | 0 Client/龚启祥/document/昆仑_大屏显示.docx | 0 Client/朱航/document/需求分析.docx | 0 Server/王琨元/document/备份导出.txt | 29 ++ Client/刘子航/document/昆仑_警报管理.docx | 0 Client/郑凯文/document/日志/郑凯文1029.doc | 0 Server/陈楚丹/document/协议适配需求分析.docx | 0 Server/马丽萍/code/log/block_queue.h | 212 +++++++++++++++++ /dev/null | 0 Client/姜可庚/document/权限管理需求分析.docx | 0 Client/宋昊昳/document/系统设置需求分析.docx | 0 Server/马丽萍/code/log/log.cpp | 166 +++++++++++++ Server/马丽萍/code/log/log.h | 97 ++++++++ Client/郑凯文/document/About version updates(第二版).docx | 0 Server/马丽萍/code/log/.vscode/settings.json | 59 ++++ Server/马丽萍/code/log/README.md | 10 Client/冀浩昶/document/生产计划管理_需求分析.docx | 0 Client/黎弘霖/document/设备管理需求分析.docx | 0 Server/王琨元/document/防注入.txt | 94 +++++-- 28 files changed, 681 insertions(+), 28 deletions(-) diff --git "a/Client/\345\206\200\346\265\251\346\230\266/document/\347\224\237\344\272\247\350\256\241\345\210\222\347\256\241\347\220\206_\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\345\206\200\346\265\251\346\230\266/document/\347\224\237\344\272\247\350\256\241\345\210\222\347\256\241\347\220\206_\351\234\200\346\261\202\345\210\206\346\236\220.docx" index 3831e20..2402a23 100644 --- "a/Client/\345\206\200\346\265\251\346\230\266/document/\347\224\237\344\272\247\350\256\241\345\210\222\347\256\241\347\220\206_\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Client/\345\206\200\346\265\251\346\230\266/document/\347\224\237\344\272\247\350\256\241\345\210\222\347\256\241\347\220\206_\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\345\210\230\345\255\220\350\210\252/document/\346\230\206\344\273\221_\350\255\246\346\212\245\347\256\241\347\220\206.docx" "b/Client/\345\210\230\345\255\220\350\210\252/document/\346\230\206\344\273\221_\350\255\246\346\212\245\347\256\241\347\220\206.docx" index 6e3fc7b..a8e3721 100644 --- "a/Client/\345\210\230\345\255\220\350\210\252/document/\346\230\206\344\273\221_\350\255\246\346\212\245\347\256\241\347\220\206.docx" +++ "b/Client/\345\210\230\345\255\220\350\210\252/document/\346\230\206\344\273\221_\350\255\246\346\212\245\347\256\241\347\220\206.docx" Binary files differ diff --git "a/Client/\345\247\234\345\217\257\345\272\232/document/\346\235\203\351\231\220\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\345\247\234\345\217\257\345\272\232/document/\346\235\203\351\231\220\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" index 4b72f8f..a879fd2 100644 --- "a/Client/\345\247\234\345\217\257\345\272\232/document/\346\235\203\351\231\220\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Client/\345\247\234\345\217\257\345\272\232/document/\346\235\203\351\231\220\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\345\256\213\346\230\212\346\230\263/document/\347\263\273\347\273\237\350\256\276\347\275\256\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\345\256\213\346\230\212\346\230\263/document/\347\263\273\347\273\237\350\256\276\347\275\256\351\234\200\346\261\202\345\210\206\346\236\220.docx" index 2819926..7ff6bde 100644 --- "a/Client/\345\256\213\346\230\212\346\230\263/document/\347\263\273\347\273\237\350\256\276\347\275\256\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Client/\345\256\213\346\230\212\346\230\263/document/\347\263\273\347\273\237\350\256\276\347\275\256\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\346\234\261\350\210\252/document/\346\234\261\350\210\252.docx" "b/Client/\346\234\261\350\210\252/document/\346\234\261\350\210\252.docx" deleted file mode 100644 index b405d28..0000000 --- "a/Client/\346\234\261\350\210\252/document/\346\234\261\350\210\252.docx" +++ /dev/null Binary files differ diff --git "a/Client/\346\234\261\350\210\252/document/\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\346\234\261\350\210\252/document/\351\234\200\346\261\202\345\210\206\346\236\220.docx" new file mode 100644 index 0000000..b94d35c --- /dev/null +++ "b/Client/\346\234\261\350\210\252/document/\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\346\235\216\345\256\265\345\242\236/document/\345\216\206\345\217\262\346\237\245\350\257\242\345\210\206\346\236\220\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\346\235\216\345\256\265\345\242\236/document/\345\216\206\345\217\262\346\237\245\350\257\242\345\210\206\346\236\220\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" index dfcc1c1..42e8c79 100644 --- "a/Client/\346\235\216\345\256\265\345\242\236/document/\345\216\206\345\217\262\346\237\245\350\257\242\345\210\206\346\236\220\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Client/\346\235\216\345\256\265\345\242\236/document/\345\216\206\345\217\262\346\237\245\350\257\242\345\210\206\346\236\220\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\347\224\263\347\203\234/document/\346\263\250\345\206\214\347\231\273\345\275\225\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\347\224\263\347\203\234/document/\346\263\250\345\206\214\347\231\273\345\275\225\351\234\200\346\261\202\345\210\206\346\236\220.docx" index 651bb8e..366835e 100644 --- "a/Client/\347\224\263\347\203\234/document/\346\263\250\345\206\214\347\231\273\345\275\225\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Client/\347\224\263\347\203\234/document/\346\263\250\345\206\214\347\231\273\345\275\225\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\351\203\221\345\207\257\346\226\207/document/About version updates\357\274\210\347\254\254\344\272\214\347\211\210\357\274\211.docx" "b/Client/\351\203\221\345\207\257\346\226\207/document/About version updates\357\274\210\347\254\254\344\272\214\347\211\210\357\274\211.docx" index 541bae5..7bcfbe4 100644 --- "a/Client/\351\203\221\345\207\257\346\226\207/document/About version updates\357\274\210\347\254\254\344\272\214\347\211\210\357\274\211.docx" +++ "b/Client/\351\203\221\345\207\257\346\226\207/document/About version updates\357\274\210\347\254\254\344\272\214\347\211\210\357\274\211.docx" Binary files differ diff --git "a/Client/\351\203\221\345\207\257\346\226\207/document/\346\227\245\345\277\227/\351\203\221\345\207\257\346\226\2071029.doc" "b/Client/\351\203\221\345\207\257\346\226\207/document/\346\227\245\345\277\227/\351\203\221\345\207\257\346\226\2071029.doc" new file mode 100644 index 0000000..0530ea7 --- /dev/null +++ "b/Client/\351\203\221\345\207\257\346\226\207/document/\346\227\245\345\277\227/\351\203\221\345\207\257\346\226\2071029.doc" Binary files differ diff --git "a/Client/\351\273\216\345\274\230\351\234\226/document/\350\256\276\345\244\207\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Client/\351\273\216\345\274\230\351\234\226/document/\350\256\276\345\244\207\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" index e248c95..8b3330d 100644 --- "a/Client/\351\273\216\345\274\230\351\234\226/document/\350\256\276\345\244\207\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Client/\351\273\216\345\274\230\351\234\226/document/\350\256\276\345\244\207\347\256\241\347\220\206\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Client/\351\276\232\345\220\257\347\245\245/document/\346\230\206\344\273\221_\345\244\247\345\261\217\346\230\276\347\244\272.docx" "b/Client/\351\276\232\345\220\257\347\245\245/document/\346\230\206\344\273\221_\345\244\247\345\261\217\346\230\276\347\244\272.docx" index 9750358..066cd87 100644 --- "a/Client/\351\276\232\345\220\257\347\245\245/document/\346\230\206\344\273\221_\345\244\247\345\261\217\346\230\276\347\244\272.docx" +++ "b/Client/\351\276\232\345\220\257\347\245\245/document/\346\230\206\344\273\221_\345\244\247\345\261\217\346\230\276\347\244\272.docx" Binary files differ diff --git "a/Server/\346\235\216\350\275\254\350\275\254/document/\351\234\200\346\261\202\345\210\206\346\236\220\346\212\245\345\221\212.docx" "b/Server/\346\235\216\350\275\254\350\275\254/document/\351\234\200\346\261\202\345\210\206\346\236\220\346\212\245\345\221\212.docx" index 9a68128..e22bd03 100644 --- "a/Server/\346\235\216\350\275\254\350\275\254/document/\351\234\200\346\261\202\345\210\206\346\236\220\346\212\245\345\221\212.docx" +++ "b/Server/\346\235\216\350\275\254\350\275\254/document/\351\234\200\346\261\202\345\210\206\346\236\220\346\212\245\345\221\212.docx" Binary files differ diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\345\215\225\344\276\213\346\250\241\345\274\217\345\260\201\350\243\205.txt" "b/Server/\347\216\213\347\220\250\345\205\203/document/\345\215\225\344\276\213\346\250\241\345\274\217\345\260\201\350\243\205.txt" deleted file mode 100644 index 2532b6c..0000000 --- "a/Server/\347\216\213\347\220\250\345\205\203/document/\345\215\225\344\276\213\346\250\241\345\274\217\345\260\201\350\243\205.txt" +++ /dev/null @@ -1,62 +0,0 @@ -#include <iostream> -#include <mutex> -#include <fstream> -#include <string> -#include <ctime> -using namespace std; -class A { -private: - ofstream logFile; - A() { - logFile.open("123.txt", ios::app); - } - ~A() { - logFile.close(); - } - A(const A &t){} - A& operator=(const A &t){} - static A* volatile s_obj; - static mutex g_mutex; -public: - static A* getInstance() { - if (s_obj == nullptr) { - lock_guard<mutex> guard(g_mutex); - if (s_obj == nullptr) { - s_obj = new A; - } - } - return s_obj; - } - void write(const string& level, const string& description, const string& time) { - logFile << "[" << level << "] " << "[" << time << "] " << description << endl; - } - void release() { - if (s_obj) { - delete s_obj; - s_obj = nullptr; - } - } -}; - -A* volatile A::s_obj = nullptr; -mutex A::g_mutex; - -int main() { - A* a1 = A::getInstance(); - A* a2 = A::getInstance(); - if (a1 == a2) { - cout << "鍗曚緥鎴愬姛" << endl; - } - else { - cout << "鍗曚緥澶辫触" << endl; - } - time_t now = time(nullptr); - char buffer[80]; - struct tm timeinfo; - localtime_s(&timeinfo, &now); - strftime(buffer, 80, "%Y - %m - %d %H:%M:%S", &timeinfo); - string timeStr(buffer); - a1->write("1", "鏃ュ織", timeStr); - a1->release(); - return 0; -} \ No newline at end of file diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\345\244\207\344\273\275\345\257\274\345\207\272.txt" "b/Server/\347\216\213\347\220\250\345\205\203/document/\345\244\207\344\273\275\345\257\274\345\207\272.txt" new file mode 100644 index 0000000..79c8216 --- /dev/null +++ "b/Server/\347\216\213\347\220\250\345\205\203/document/\345\244\207\344\273\275\345\257\274\345\207\272.txt" @@ -0,0 +1,29 @@ +#!/bin/bash + +# 鏁版嵁搴撹繛鎺ュ弬鏁� +DB_USER="your_username" +DB_PASS="your_password" +DB_NAME="your_database_name" +BACKUP_DIR="/path/to/backup/directory" + +# 鑾峰彇褰撳墠鏃ユ湡锛岀敤浜庢枃浠跺悕 +DATE=$(date +%Y%m%d%H%M%S) + +# 澶囦唤鏂囦欢鍚� +BACKUP_FILE="${BACKUP_DIR}/backup_${DATE}.sql" + +# 鍒涘缓澶囦唤鐩綍锛堝鏋滀笉瀛樺湪锛� +mkdir -p $BACKUP_DIR + +# 浣跨敤mysqldump杩涜鏁版嵁搴撳浠� +mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_FILE + +if [ $? -eq 0 ]; then + echo "鏁版嵁搴撳浠芥垚鍔燂細$BACKUP_FILE" +else + echo "鏁版嵁搴撳浠藉け璐�" +fi + +# 娣诲姞瀹氭椂浠诲姟锛堜娇鐢╟rontab -e鏉ョ紪杈戝畾鏃朵换鍔★級 +# 渚嬪锛屾瘡澶╁噷鏅�2鐐规墽琛屽浠� +# 0 2 * * * /path/to/this/script.sh \ No newline at end of file diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\345\273\272\350\241\250.docx" "b/Server/\347\216\213\347\220\250\345\205\203/document/\345\273\272\350\241\250.docx" new file mode 100644 index 0000000..b777db4 --- /dev/null +++ "b/Server/\347\216\213\347\220\250\345\205\203/document/\345\273\272\350\241\250.docx" Binary files differ diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223.docx" "b/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223.docx" deleted file mode 100644 index c7dd41d..0000000 --- "a/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223.docx" +++ /dev/null Binary files differ diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" new file mode 100644 index 0000000..22d785e --- /dev/null +++ "b/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223\346\250\241\345\235\227\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223\350\277\236\346\216\245.txt" "b/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223\350\277\236\346\216\245.txt" deleted file mode 100644 index dad6734..0000000 --- "a/Server/\347\216\213\347\220\250\345\205\203/document/\346\225\260\346\215\256\345\272\223\350\277\236\346\216\245.txt" +++ /dev/null @@ -1,16 +0,0 @@ -#include "MySQL.h" -#include <WinSock2.h> -#include <mysql.h> -#include <iostream> -#include <string> -using namespace std; -int main() { - MYSQL mysql; - mysql_init(&mysql);//鍒濆鍖� - //杩炴帴鏁版嵁搴撴湇鍔″櫒鏈嶅姟鍣� IP 鐢ㄦ埛鍚� 瀵嗙爜 鏁版嵁搴撶鍙e彿 - mysql_real_connect(&mysql, "192.168.136.128", "root", "123456", "wang", 3306, NULL, 0); - - string sql="set names gbk"; - mysql_real_query(&mysql, sql.c_str(), sql.size()); - mysql_close(&mysql); - return 0; \ No newline at end of file diff --git "a/Server/\347\216\213\347\220\250\345\205\203/document/\351\230\262\346\263\250\345\205\245.txt" "b/Server/\347\216\213\347\220\250\345\205\203/document/\351\230\262\346\263\250\345\205\245.txt" index 09b9217..19a2f6c 100644 --- "a/Server/\347\216\213\347\220\250\345\205\203/document/\351\230\262\346\263\250\345\205\245.txt" +++ "b/Server/\347\216\213\347\220\250\345\205\203/document/\351\230\262\346\263\250\345\205\245.txt" @@ -1,29 +1,67 @@ -https://blog.csdn.net/qq_28245087/article/details/131453274 -1 .浣跨敤鍙傛暟鍖栨煡璇� -浣跨敤鍙傛暟鍖栨煡璇㈠彲浠ラ槻姝QL娉ㄥ叆鏀诲嚮锛屽苟鎻愰珮浠g爜鐨勫彲璇绘�у拰鍙淮鎶ゆ�с�傚湪Java涓紝鍙互浣跨敤PreparedStatement鏉ュ疄鐜板弬鏁板寲鏌ヨ銆� -2. 杈撳叆楠岃瘉鍜岃繃婊� -杈撳叆楠岃瘉鍜岃繃婊ゆ槸涓�绉嶇敤浜庣‘淇濈敤鎴疯緭鍏ユ暟鎹殑瀹夊叏鎬у拰鏈夋晥鎬х殑鎶�鏈�傚畠鍙互闃叉鎭舵剰杈撳叆鍜岄敊璇暟鎹鑷寸殑瀹夊叏婕忔礊鍜屽簲鐢ㄧ▼搴忛敊璇�� -3. 浣跨敤瀛樺偍杩囩▼ -瀛樺偍杩囩▼鏄竴缁勯瀹氫箟鐨凷QL璇彞闆嗗悎锛屽彲浠ュ湪鏁版嵁搴撲腑杩涜閲嶅鎬у拰澶嶆潅鎬х殑鎿嶄綔銆傚畠浠彲浠ユ帴鍙楀弬鏁帮紝骞朵笖鍙互鍦ㄦ暟鎹簱涓繘琛岄噸澶嶄娇鐢ㄣ�� -4.鏈�灏忔潈闄愬師鍒� -鏈�灏忔潈闄愬師鍒欐槸涓�绉嶅畨鍏ㄦ�у師鍒欙紝鎸囩殑鏄负浜嗕繚鎶ゆ晱鎰熸暟鎹拰绯荤粺璧勬簮锛岀敤鎴峰簲璇ヨ鎺堜簣鏈�灏忓繀闇�鐨勬潈闄愩�傝繖鎰忓懗鐫�鐢ㄦ埛鍙兘璁块棶鍜屾墽琛屼粬浠伐浣滄墍闇�鐨勬暟鎹簱瀵硅薄鍜屾搷浣滐紝鑰屼笉鏄嫢鏈夊鏁翠釜鏁版嵁搴撶殑瀹屽叏璁块棶鏉冮檺銆� -浣跨敤鏈�灏忔潈闄愬師鍒欏彲浠ュ噺灏戞綔鍦ㄧ殑瀹夊叏椋庨櫓鍜屾暟鎹硠闇茬殑鍙兘鎬с�傞�氳繃闄愬埗鐢ㄦ埛鐨勬潈闄愶紝鍙互闃叉浠栦滑瀵规暟鎹簱涓殑鏁忔劅鏁版嵁杩涜鏈粡鎺堟潈鐨勮闂�佷慨鏀规垨鍒犻櫎銆� -5. 浣跨敤ORM妗嗘灦 -ORM锛堝璞″叧绯绘槧灏勶級妗嗘灦鏄竴绉嶅皢瀵硅薄妯″瀷鍜屽叧绯绘暟鎹簱涔嬮棿杩涜鏄犲皠鐨勬妧鏈�傚畠鍏佽寮�鍙戜汉鍛樹娇鐢ㄩ潰鍚戝璞$殑鏂瑰紡鎿嶄綔鏁版嵁搴擄紝鑰屼笉闇�瑕佺紪鍐欑箒鐞愮殑SQL璇彞銆侽RM妗嗘灦灏嗘暟鎹簱琛ㄦ槧灏勪负瀵硅薄锛屽皢琛ㄧ殑琛屾槧灏勪负瀵硅薄鐨勫睘鎬э紝灏嗚〃涔嬮棿鐨勫叧绯绘槧灏勪负瀵硅薄涔嬮棿鐨勫叧鑱斻�� -ORM妗嗘灦鐨勪紭鐐瑰寘鎷彁楂樺紑鍙戞晥鐜囥�佸噺灏戜唬鐮侀噺銆佺畝鍖栨暟鎹簱鎿嶄綔銆佹彁渚涘璞$骇鍒殑鏌ヨ鍜屾寔涔呭寲绛夈�� -6. 浣跨敤鍑嗗璇彞 -鍑嗗璇彞锛圥repared Statement锛夋槸涓�绉嶉缂栬瘧鐨凷QL璇彞锛屽畠鍏佽寮�鍙戜汉鍛樺皢鍙傛暟鍖栨煡璇㈠彂閫佸埌鏁版嵁搴擄紝骞跺湪鎵ц鏃舵彁渚涘弬鏁板�笺�傚噯澶囪鍙ュ彲浠ユ彁楂樻暟鎹簱鎿嶄綔鐨勬�ц兘鍜屽畨鍏ㄦ�э紝鍚屾椂杩樿兘闃叉SQL娉ㄥ叆鏀诲嚮銆� -7.浣跨敤瀹夊叏鐨勬暟鎹簱杩炴帴 -浣跨敤瀹夊叏鐨勬暟鎹簱杩炴帴鏄潪甯搁噸瑕佺殑锛屽彲浠ヤ繚鎶ゆ暟鎹簱鍏嶅彈鎭舵剰鏀诲嚮鍜屾暟鎹硠闇层�� -浣跨敤SSL/TLS鍔犲瘑锛氶�氳繃浣跨敤SSL/TLS鍔犲瘑锛屽彲浠ョ‘淇濇暟鎹簱杩炴帴鍦ㄤ紶杈撹繃绋嬩腑鐨勬暟鎹畨鍏ㄣ�� -8.閬垮厤鍔ㄦ�佹嫾鎺QL璇彞 -閬垮厤鍔ㄦ�佹嫾鎺QL璇彞鏄负浜嗛槻姝QL娉ㄥ叆鏀诲嚮鍜屾彁楂樹唬鐮佺殑鍙鎬у拰鍙淮鎶ゆ�с�� -9.浣跨敤闃茬伀澧欏拰鍏ヤ镜妫�娴嬬郴缁� -浣跨敤闃茬伀澧欏拰鍏ヤ镜妫�娴嬬郴缁熸槸涓轰簡淇濇姢璁$畻鏈虹綉缁滃厤鍙楁湭缁忔巿鏉冪殑璁块棶鍜屾伓鎰忔敾鍑汇�� -10.瀹氭湡鏇存柊鍜岀淮鎶ゆ暟鎹簱杞欢 -瀹氭湡鏇存柊鍜岀淮鎶ゆ暟鎹簱杞欢鏄潪甯搁噸瑕佺殑锛屼互纭繚鏁版嵁搴撶殑瀹夊叏鎬с�佹�ц兘鍜屽姛鑳界殑绋冲畾鎬с�備互涓嬫槸涓�浜涜鏄庡拰瑙i噴锛屼互鍙婁娇鐢↗ava浠g爜绀轰緥鏉ュ疄鐜版暟鎹簱杞欢鐨勫畾鏈熸洿鏂板拰缁存姢锛� +#include <iostream> +#include <mysql_driver.h> +#include <mysql_connection.h> +#include <cppconn/statement.h> +#include <cppconn/prepared_statement.h> +#include <cppconn/resultset.h> +#include <string> +#include <regex> -瀹氭湡鏇存柊锛� -瀹氭湡鏇存柊鏁版嵁搴撹蒋浠舵槸涓轰簡鑾峰彇鏈�鏂扮殑瀹夊叏琛ヤ竵銆佸姛鑳芥敼杩涘拰鎬ц兘浼樺寲銆傛暟鎹簱渚涘簲鍟嗛�氬父浼氬彂甯冩洿鏂扮増鏈紝浠ヤ慨澶嶅凡鐭ョ殑婕忔礊鍜岄棶棰樸�傛洿鏂版暟鎹簱杞欢鍙互鎻愰珮鏁版嵁搴撶殑瀹夊叏鎬э紝骞剁‘淇濇暟鎹簱涓庢渶鏂扮殑鎶�鏈拰鏍囧噯淇濇寔涓�鑷淬�� -缁存姢浠诲姟锛� -鏁版嵁搴撹蒋浠剁殑缁存姢浠诲姟鍖呮嫭澶囦唤鍜屾仮澶嶃�佺储寮曚紭鍖栥�佺粺璁′俊鎭洿鏂般�佺┖闂寸鐞嗐�佹棩蹇楃鐞嗙瓑銆傝繖浜涗换鍔℃湁鍔╀簬鎻愰珮鏁版嵁搴撶殑鎬ц兘銆佸彲鐢ㄦ�у拰鍙潬鎬с�� +class DatabaseUtils { +public: + // 杩炴帴鏁版嵁搴� + static sql::Connection* connect() { + try { + sql::mysql::MySQL_Driver* driver = sql::mysql::get_mysql_driver_instance(); + sql::Connection* con = driver->connect("tcp://127.0.0.1:3306", "mayi", "123456"); + con->setSchema("your_database"); + return con; + } catch (sql::SQLException& e) { + std::cerr << "鏁版嵁搴撹繛鎺ラ敊璇�: " << e.what() << std::endl; + return nullptr; + } + } + + // 妫�鏌QL璇彞鏄惁瀛樺湪娼滃湪娉ㄥ叆椋庨櫓锛堢畝鍗曟鍒欐牎楠岋級 + static bool isSafeSQL(const std::string& sql) { + // 绠�鍗曠殑姝e垯琛ㄨ揪寮忥紝闃叉甯歌鐨勬敞鍏ュ叧閿瘝 + std::regex injectionRegex("(drop|delete|update|insert|select\\s+\\*\\s+from)", std::regex_constants::icase); + return!std::regex_search(sql, injectionRegex); + } + + // 浣跨敤鍙傛暟鍖栨煡璇㈡墽琛孲QL璇彞 + static sql::ResultSet* executeSafeQuery(sql::Connection* con, const std::string& sql, const std::vector<std::string>& params) { + try { + sql::PreparedStatement* pstmt = con->prepareStatement(sql); + for (size_t i = 0; i < params.size(); ++i) { + pstmt->setString(i + 1, params[i]); + } + return pstmt->executeQuery(); + } catch (sql::SQLException& e) { + std::cerr << "鏌ヨ鎵ц閿欒: " << e.what() << std::endl; + return nullptr; + } + } +}; + +int main() { + sql::Connection* con = DatabaseUtils::connect(); + if (con) { + std::string sql = "SELECT * FROM your_table WHERE column_name =?"; + std::vector<std::string> params = {"test_value"}; + if (DatabaseUtils::isSafeSQL(sql)) { + sql::ResultSet* res = DatabaseUtils::executeSafeQuery(con, sql, params); + if (res) { + while (res->next()) { + // 澶勭悊缁撴灉 + std::cout << res->getString(1) << std::endl; + } + delete res; + } + } else { + std::cerr << "娼滃湪鐨凷QL娉ㄥ叆椋庨櫓" << std::endl; + } + delete con; + } + return 0; +} \ No newline at end of file diff --git "a/Server/\350\203\241\345\256\266\346\230\216/document/\347\275\221\347\273\234socket\346\220\255\345\273\272\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Server/\350\203\241\345\256\266\346\230\216/document/\347\275\221\347\273\234socket\346\220\255\345\273\272\351\234\200\346\261\202\345\210\206\346\236\220.docx" index 16a5c4e..7e1ce8a 100644 --- "a/Server/\350\203\241\345\256\266\346\230\216/document/\347\275\221\347\273\234socket\346\220\255\345\273\272\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Server/\350\203\241\345\256\266\346\230\216/document/\347\275\221\347\273\234socket\346\220\255\345\273\272\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Server/\351\231\210\346\245\232\344\270\271/document/\345\215\217\350\256\256\351\200\202\351\205\215\351\234\200\346\261\202\345\210\206\346\236\220.docx" "b/Server/\351\231\210\346\245\232\344\270\271/document/\345\215\217\350\256\256\351\200\202\351\205\215\351\234\200\346\261\202\345\210\206\346\236\220.docx" index 77f911d..e1b4789 100644 --- "a/Server/\351\231\210\346\245\232\344\270\271/document/\345\215\217\350\256\256\351\200\202\351\205\215\351\234\200\346\261\202\345\210\206\346\236\220.docx" +++ "b/Server/\351\231\210\346\245\232\344\270\271/document/\345\215\217\350\256\256\351\200\202\351\205\215\351\234\200\346\261\202\345\210\206\346\236\220.docx" Binary files differ diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/c_cpp_properties.json" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/c_cpp_properties.json" new file mode 100644 index 0000000..cea4d3f --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/c_cpp_properties.json" @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/launch.json" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/launch.json" new file mode 100644 index 0000000..6d3cc50 --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/launch.json" @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "d:/git_1026/鏄嗕粦_1025/Server/椹附钀�/code/log", + "program": "d:/git_1026/鏄嗕粦_1025/Server/椹附钀�/code/log/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/settings.json" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/settings.json" new file mode 100644 index 0000000..c9e66f1 --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/.vscode/settings.json" @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/README.md" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/README.md" new file mode 100644 index 0000000..6a1cf51 --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/README.md" @@ -0,0 +1,10 @@ + +寮傛鏃ュ織绯荤粺 +=============== +寮傛鏃ュ織绯荤粺涓昏娑夊強浜嗕袱涓ā鍧楋紝涓�涓槸鏃ュ織妯″潡锛屼竴涓槸闃诲闃熷垪妯″潡,鍏朵腑鍔犲叆闃诲闃熷垪妯″潡涓昏鏄В鍐冲紓姝ュ啓鍏ユ棩蹇楀仛鍑嗗. +> * 鑷畾涔夐樆濉為槦鍒� +> * 鍗曚緥妯″紡鍒涘缓鏃ュ織 +> * 鍚屾鏃ュ織 +> * 寮傛鏃ュ織 +> * 瀹炵幇鎸夊ぉ銆佽秴琛屽垎绫� +> * 鏂囦欢闄愬埗澶у皬 闃叉鏃ュ織鏂囦欢杩囧ぇ \ No newline at end of file diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/block_queue.h" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/block_queue.h" new file mode 100644 index 0000000..34c77bd --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/block_queue.h" @@ -0,0 +1,212 @@ +/************************************************************* +*寰幆鏁扮粍瀹炵幇鐨勯樆濉為槦鍒楋紝m_back = (m_back + 1) % m_max_size; +*绾跨▼瀹夊叏锛屾瘡涓搷浣滃墠閮借鍏堝姞浜掓枼閿侊紝鎿嶄綔瀹屽悗锛屽啀瑙i攣 +**************************************************************/ + +#ifndef BLOCK_QUEUE_H +#define BLOCK_QUEUE_H + +#include <iostream> +#include <stdlib.h> +#include <pthread.h> +#include <sys/time.h> +#include "../lock/locker.h" +using namespace std; + +template <class T> +class block_queue +{ +public: + block_queue(int max_size = 1000) + { + if (max_size <= 0) + { + exit(-1); + } + + m_max_size = max_size; + m_array = new T[max_size]; + m_size = 0; + m_front = -1; + m_back = -1; + } + + void clear() + { + m_mutex.lock(); + m_size = 0; + m_front = -1; + m_back = -1; + m_mutex.unlock(); + } + + ~block_queue() + { + m_mutex.lock(); + if (m_array != NULL) + delete [] m_array; + + m_mutex.unlock(); + } + //鍒ゆ柇闃熷垪鏄惁婊′簡 + bool full() + { + m_mutex.lock(); + if (m_size >= m_max_size) + { + + m_mutex.unlock(); + return true; + } + m_mutex.unlock(); + return false; + } + //鍒ゆ柇闃熷垪鏄惁涓虹┖ + bool empty() + { + m_mutex.lock(); + if (0 == m_size) + { + m_mutex.unlock(); + return true; + } + m_mutex.unlock(); + return false; + } + //杩斿洖闃熼鍏冪礌 + bool front(T &value) + { + m_mutex.lock(); + if (0 == m_size) + { + m_mutex.unlock(); + return false; + } + value = m_array[m_front]; + m_mutex.unlock(); + return true; + } + //杩斿洖闃熷熬鍏冪礌 + bool back(T &value) + { + m_mutex.lock(); + if (0 == m_size) + { + m_mutex.unlock(); + return false; + } + value = m_array[m_back]; + m_mutex.unlock(); + return true; + } + + int size() + { + int tmp = 0; + + m_mutex.lock(); + tmp = m_size; + + m_mutex.unlock(); + return tmp; + } + + int max_size() + { + int tmp = 0; + + m_mutex.lock(); + tmp = m_max_size; + + m_mutex.unlock(); + return tmp; + } + //寰�闃熷垪娣诲姞鍏冪礌锛岄渶瑕佸皢鎵�鏈変娇鐢ㄩ槦鍒楃殑绾跨▼鍏堝敜閱� + //褰撴湁鍏冪礌push杩涢槦鍒�,鐩稿綋浜庣敓浜ц�呯敓浜т簡涓�涓厓绱� + //鑻ュ綋鍓嶆病鏈夌嚎绋嬬瓑寰呮潯浠跺彉閲�,鍒欏敜閱掓棤鎰忎箟 + bool push(const T &item) + { + + m_mutex.lock(); + if (m_size >= m_max_size) + { + + m_cond.broadcast(); + m_mutex.unlock(); + return false; + } + + m_back = (m_back + 1) % m_max_size; + m_array[m_back] = item; + + m_size++; + + m_cond.broadcast(); + m_mutex.unlock(); + return true; + } + //pop鏃�,濡傛灉褰撳墠闃熷垪娌℃湁鍏冪礌,灏嗕細绛夊緟鏉′欢鍙橀噺 + bool pop(T &item) + { + + m_mutex.lock(); + while (m_size <= 0) + { + + if (!m_cond.wait(m_mutex.get())) + { + m_mutex.unlock(); + return false; + } + } + + m_front = (m_front + 1) % m_max_size; + item = m_array[m_front]; + m_size--; + m_mutex.unlock(); + return true; + } + + //澧炲姞浜嗚秴鏃跺鐞� + bool pop(T &item, int ms_timeout) + { + struct timespec t = {0, 0}; + struct timeval now = {0, 0}; + gettimeofday(&now, NULL); + m_mutex.lock(); + if (m_size <= 0) + { + t.tv_sec = now.tv_sec + ms_timeout / 1000; + t.tv_nsec = (ms_timeout % 1000) * 1000; + if (!m_cond.timewait(m_mutex.get(), t)) + { + m_mutex.unlock(); + return false; + } + } + + if (m_size <= 0) + { + m_mutex.unlock(); + return false; + } + + m_front = (m_front + 1) % m_max_size; + item = m_array[m_front]; + m_size--; + m_mutex.unlock(); + return true; + } + +private: + locker m_mutex; + cond m_cond; + + T *m_array; + int m_size; + int m_max_size; + int m_front; + int m_back; +}; + +#endif diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/log.cpp" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/log.cpp" new file mode 100644 index 0000000..7368c50 --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/log.cpp" @@ -0,0 +1,166 @@ +#include <string.h> +#include <time.h> +#include <sys/time.h> +#include <stdarg.h> +#include "log.h" +#include <pthread.h> +using namespace std; + +Log::Log() +{ + m_count = 0; + m_is_async = false; +} + +Log::~Log() +{ + if (m_fp != NULL) + { + fclose(m_fp); + } +} + +bool Log::init(const char *file_name, int close_log, int log_buf_size, int split_lines, int max_queue_size) +{ + if (max_queue_size >= 1) + { + m_is_async = true; + m_log_queue = new block_queue<string>(max_queue_size); + pthread_t tid; + pthread_create(&tid, NULL, flush_log_thread, NULL); + } + + m_close_log = close_log; + m_log_buf_size = log_buf_size; + m_buf = new char[m_log_buf_size]; + memset(m_buf, '\0', m_log_buf_size); + m_split_lines = split_lines; + + time_t t = time(NULL); + struct tm *sys_tm = localtime(&t); + const char *p = strrchr(file_name, '/'); + char log_full_name[256] = {0}; + + if (p == NULL) + { + snprintf(log_full_name, 255, "%d_%02d_%02d_%s", sys_tm->tm_year + 1900, sys_tm->tm_mon + 1, sys_tm->tm_mday, file_name); + } + else + { + strcpy(log_name, p + 1); + strncpy(dir_name, file_name, p - file_name + 1); + snprintf(log_full_name, 255, "%s%d_%02d_%02d_%s", dir_name, sys_tm->tm_year + 1900, sys_tm->tm_mon + 1, sys_tm->tm_mday, log_name); + } + + m_today = sys_tm->tm_mday; + m_fp = fopen(log_full_name, "a"); + if (m_fp == NULL) + { + return false; + } + + return true; +} + +void Log::write_log(int level, const char *format, ...) +{ + struct timeval now; + gettimeofday(&now, NULL); + time_t t = now.tv_sec; + struct tm *sys_tm = localtime(&t); + char s[16] = {0}; + + switch (level) + { + case 0: strcpy(s, "[debug]:"); break; + case 1: strcpy(s, "[info]:"); break; + case 2: strcpy(s, "[warn]:"); break; + case 3: strcpy(s, "[erro]:"); break; + default: strcpy(s, "[info]:"); break; + } + + m_mutex.lock(); + m_count++; + + if (m_today != sys_tm->tm_mday || m_count % m_split_lines == 0) + { + char new_log[256] = {0}; + fflush(m_fp); + fclose(m_fp); + char tail[16] = {0}; + snprintf(tail, 16, "%d_%02d_%02d_", sys_tm->tm_year + 1900, sys_tm->tm_mon + 1, sys_tm->tm_mday); + + if (m_today != sys_tm->tm_mday) + { + snprintf(new_log, 255, "%s%s%s", dir_name, tail, log_name); + m_today = sys_tm->tm_mday; + m_count = 0; + } + else + { + snprintf(new_log, 255, "%s%s%s.%lld", dir_name, tail, log_name, m_count / m_split_lines); + } + m_fp = fopen(new_log, "a"); + } + + // 鍦ㄥ啓鍏ヤ箣鍓嶆鏌ユ棩蹇楁枃浠跺ぇ灏� + if (check_log_size()) + { + rotate_logs(); // 濡傛灉瓒呰繃鏈�澶ф枃浠跺ぇ灏忥紝杩涜鏃ュ織杞崲 + } + + va_list valst; + va_start(valst, format); + + string log_str; + int n = snprintf(m_buf, 48, "%d-%02d-%02d %02d:%02d:%02d.%06ld %s ", + sys_tm->tm_year + 1900, sys_tm->tm_mon + 1, sys_tm->tm_mday, + sys_tm->tm_hour, sys_tm->tm_min, sys_tm->tm_sec, now.tv_usec, s); + int m = vsnprintf(m_buf + n, m_log_buf_size - n - 1, format, valst); + m_buf[n + m] = '\n'; + m_buf[n + m + 1] = '\0'; + log_str = m_buf; + + m_mutex.unlock(); + + if (m_is_async && !m_log_queue->full()) + { + m_log_queue->push(log_str); + } + else + { + m_mutex.lock(); + fputs(log_str.c_str(), m_fp); + m_mutex.unlock(); + } + + va_end(valst); +} + +void Log::flush(void) +{ + m_mutex.lock(); + fflush(m_fp); + m_mutex.unlock(); +} + +// 娣诲姞鐨勬枃浠跺ぇ灏忔鏌ュ嚱鏁� +bool Log::check_log_size() +{ + if (m_fp) + { + fseek(m_fp, 0, SEEK_END); + long file_size = ftell(m_fp); + return file_size >= max_size; // 杩斿洖鏂囦欢鏄惁瓒呭嚭闄愬埗 + } + return false; +} + +void Log::rotate_logs() +{ + fclose(m_fp); // 鍏抽棴褰撳墠鏃ュ織鏂囦欢 + char new_log[256] = {0}; + snprintf(new_log, sizeof(new_log), "%s/%s.%lld", dir_name, log_name, m_count / m_split_lines); + m_fp = fopen(new_log, "a"); // 鎵撳紑鏂扮殑鏃ュ織鏂囦欢 + m_count = 0; // 閲嶇疆鏃ュ織璁℃暟 +} diff --git "a/Server/\351\251\254\344\270\275\350\220\215/code/log/log.h" "b/Server/\351\251\254\344\270\275\350\220\215/code/log/log.h" new file mode 100644 index 0000000..e0f2c25 --- /dev/null +++ "b/Server/\351\251\254\344\270\275\350\220\215/code/log/log.h" @@ -0,0 +1,97 @@ +#ifndef LOG_H +#define LOG_H + +#include <stdio.h> +#include <iostream> +#include <string> +#include <stdarg.h> +#include <pthread.h> +#include "block_queue.h" + +using namespace std; + +class Log +{ +public: + // C++11浠ュ悗,浣跨敤灞�閮ㄥ彉閲忔噿姹変笉鐢ㄥ姞閿� + static Log *get_instance() + { + static Log instance; + return &instance; + } + + static void *flush_log_thread(void *args) + { + Log::get_instance()->async_write_log(); + } + + // 鍙�夋嫨鐨勫弬鏁版湁鏃ュ織鏂囦欢銆佹棩蹇楃紦鍐插尯澶у皬銆佹渶澶ц鏁颁互鍙婃渶闀挎棩蹇楁潯闃熷垪 + bool init(const char *file_name, int close_log, int log_buf_size = 8192, int split_lines = 5000000, int max_queue_size = 0); + + void write_log(int level, const char *format, ...); + void flush(void); + +private: + Log(); + virtual ~Log(); + + void *async_write_log() + { + string single_log; + // 浠庨樆濉為槦鍒椾腑鍙栧嚭涓�涓棩蹇梥tring锛屽啓鍏ユ枃浠� + while (m_log_queue->pop(single_log)) + { + m_mutex.lock(); + if (check_log_size()) // 妫�鏌ユ枃浠跺ぇ灏� + { + rotate_logs(); // 杞崲鏃ュ織 + } + fputs(single_log.c_str(), m_fp); + m_mutex.unlock(); + } + } + + // 妫�鏌ユ棩蹇楁枃浠跺ぇ灏� + bool check_log_size() + { + if (m_fp) + { + fseek(m_fp, 0, SEEK_END); + long file_size = ftell(m_fp); + return file_size >= max_size; // 杩斿洖鏂囦欢鏄惁瓒呭嚭闄愬埗 + } + return false; + } + + // 杞崲鏃ュ織鏂囦欢 + void rotate_logs() + { + fclose(m_fp); // 鍏抽棴褰撳墠鏃ュ織鏂囦欢 + char new_log[256] = {0}; + snprintf(new_log, sizeof(new_log), "%s/%s.%lld", dir_name, log_name, m_count / m_split_lines); + m_fp = fopen(new_log, "a"); // 鎵撳紑鏂扮殑鏃ュ織鏂囦欢 + m_count = 0; // 閲嶇疆鏃ュ織璁℃暟 + } + +private: + char dir_name[128]; // 璺緞鍚� + char log_name[128]; // log鏂囦欢鍚� + int m_split_lines; // 鏃ュ織鏈�澶ц鏁� + int m_log_buf_size; // 鏃ュ織缂撳啿鍖哄ぇ灏� + long long m_count; // 鏃ュ織琛屾暟璁板綍 + int m_today; // 鍥犱负鎸夊ぉ鍒嗙被,璁板綍褰撳墠鏃堕棿鏄偅涓�澶� + FILE *m_fp; // 鎵撳紑log鐨勬枃浠舵寚閽� + char *m_buf; + block_queue<string> *m_log_queue; // 闃诲闃熷垪 + bool m_is_async; // 鏄惁鍚屾鏍囧織浣� + locker m_mutex; + int m_close_log; // 鍏抽棴鏃ュ織 + long max_size = 10 * 1024 * 1024; // 10MB +}; + +#define LOG_DEBUG(format, ...) if(0 == m_close_log) {Log::get_instance()->write_log(0, format, ##__VA_ARGS__); Log::get_instance()->flush();} +#define LOG_INFO(format, ...) if(0 == m_close_log) {Log::get_instance()->write_log(1, format, ##__VA_ARGS__); Log::get_instance()->flush();} +#define LOG_WARN(format, ...) if(0 == m_close_log) {Log::get_instance()->write_log(2, format, ##__VA_ARGS__); Log::get_instance()->flush();} +#define LOG_ERROR(format, ...) if(0 == m_close_log) {Log::get_instance()->write_log(3, format, ##__VA_ARGS__); Log::get_instance()->flush();} + +#endif diff --git "a/Server/\351\251\254\346\270\235\346\235\255/document/\347\211\210\346\234\254\346\233\264\346\226\260\345\212\237\350\203\275\351\234\200\346\261\202_server.docx" "b/Server/\351\251\254\346\270\235\346\235\255/document/\347\211\210\346\234\254\346\233\264\346\226\260\345\212\237\350\203\275\351\234\200\346\261\202_server.docx" index 434dbef..a9b7748 100644 --- "a/Server/\351\251\254\346\270\235\346\235\255/document/\347\211\210\346\234\254\346\233\264\346\226\260\345\212\237\350\203\275\351\234\200\346\261\202_server.docx" +++ "b/Server/\351\251\254\346\270\235\346\235\255/document/\347\211\210\346\234\254\346\233\264\346\226\260\345\212\237\350\203\275\351\234\200\346\261\202_server.docx" Binary files differ diff --git "a/\345\217\202\350\200\203\346\226\207\346\241\243/\351\234\200\346\261\202\345\210\206\346\236\220\346\250\241\346\235\277/~$\346\261\202\345\212\237\350\203\275\350\247\204\346\240\274\350\257\264\346\230\216\344\271\246_2.docx" "b/\345\217\202\350\200\203\346\226\207\346\241\243/\351\234\200\346\261\202\345\210\206\346\236\220\346\250\241\346\235\277/~$\346\261\202\345\212\237\350\203\275\350\247\204\346\240\274\350\257\264\346\230\216\344\271\246_2.docx" deleted file mode 100644 index 91ee577..0000000 --- "a/\345\217\202\350\200\203\346\226\207\346\241\243/\351\234\200\346\261\202\345\210\206\346\236\220\346\250\241\346\235\277/~$\346\261\202\345\212\237\350\203\275\350\247\204\346\240\274\350\257\264\346\230\216\344\271\246_2.docx" +++ /dev/null Binary files differ diff --git "a/\346\230\206\344\273\221\351\241\271\347\233\256\346\226\207\344\273\266/\346\230\206\344\273\221\351\241\271\347\233\256\351\243\216\351\231\251\347\256\241\347\220\206\350\241\250.xlsx" "b/\346\230\206\344\273\221\351\241\271\347\233\256\346\226\207\344\273\266/\346\230\206\344\273\221\351\241\271\347\233\256\351\243\216\351\231\251\347\256\241\347\220\206\350\241\250.xlsx" index 2053e12..d4535c8 100644 --- "a/\346\230\206\344\273\221\351\241\271\347\233\256\346\226\207\344\273\266/\346\230\206\344\273\221\351\241\271\347\233\256\351\243\216\351\231\251\347\256\241\347\220\206\350\241\250.xlsx" +++ "b/\346\230\206\344\273\221\351\241\271\347\233\256\346\226\207\344\273\266/\346\230\206\344\273\221\351\241\271\347\233\256\351\243\216\351\231\251\347\256\241\347\220\206\350\241\250.xlsx" Binary files differ -- Gitblit v1.8.0