优化: ssh/mongo/redis-proxy 超时分级与日志默认开
- ssh: exec_timeout_secs 600s(408断会话)/idle 300→1800s/日志级别规则/截断500→2000 - mongo/redis: query_timeout 60s + idle_timeout 落配置 - 四代理: 日志默认开启(default_log_path exe同目录logs/),未设env也记录 - mysql: default_log_path 共享实现注释同步
This commit is contained in:
1 parent
ecdebdd6c0
commit
95dfe8504d
20 files changed
+3494
-121
No files matched your search
@@ -123,13 +123,13 @@ impl LogEntry {
|
||||
|
||||
pub fn with_sql(mut self, sql: &str) -> Self {
|
||||
// 截断过长的 SQL
|
||||
self.sql = Some(truncate_string(sql, 1000));
|
||||
self.sql = Some(truncate_string(sql, 2000));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_command(mut self, command: &str) -> Self {
|
||||
// 截断过长的命令
|
||||
self.command = Some(truncate_string(command, 500));
|
||||
self.command = Some(truncate_string(command, 2000));
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -64,6 +64,17 @@ enum Commands {
|
||||
}
|
||||
|
||||
// ⚠ 共享实现,修改需同步至 ssh/mongo/redis-proxy/src/main.rs
|
||||
/// 默认请求日志路径(未设置 MYSQL_PROXY_LOG 时): exe同目录 logs/mysql-proxy.log
|
||||
/// 日志默认开启——此前需手动设 env 才记录,排查只能靠复现
|
||||
fn default_log_path(name: &str) -> String {
|
||||
match std::env::current_exe() {
|
||||
Ok(exe) => exe.parent()
|
||||
.map(|d| d.join("logs").join(format!("{}.log", name)).to_string_lossy().into_owned())
|
||||
.unwrap_or_else(|| format!("{}.log", name)),
|
||||
Err(_) => format!("{}.log", name),
|
||||
}
|
||||
}
|
||||
|
||||
/// 将相对路径基于可执行文件所在目录解析为绝对路径
|
||||
fn resolve_config_path(path: &str) -> String {
|
||||
if std::path::Path::new(path).is_absolute() || path.starts_with('~') {
|
||||
@@ -118,7 +129,8 @@ async fn run_server(config_path: &str, port: Option<u16>, host: Option<String>)
|
||||
}
|
||||
|
||||
// 初始化日志
|
||||
let log_path = std::env::var("MYSQL_PROXY_LOG").ok();
|
||||
let log_path = std::env::var("MYSQL_PROXY_LOG").ok()
|
||||
.or_else(|| Some(default_log_path("mysql-proxy")));
|
||||
let logger = Arc::new(logger::RequestLogger::new(log_path.as_deref()));
|
||||
if logger.is_enabled() {
|
||||
println!("Request logging: enabled");
|
||||
|
||||
Reference in new issue
Block a user