refactor(logging): 统一日志前缀,删除废弃的 LogBase

- 删除 LogBase 函数,所有调用迁移到 LogInfo/LogError
- 新增 PrefixDebug ([.]) 前缀,所有日志级别现在都有前缀
- 修复日志输出缩进不一致的问题
- 删除未使用的 PrefixDefault 常量
This commit is contained in:
ZacharyZcR
2026-01-21 18:29:47 +08:00
parent 5e04ad97e7
commit 8312808769
15 changed files with 46 additions and 47 deletions
+2 -2
View File
@@ -237,9 +237,9 @@ func (b *BaseScanStrategy) LogScanStart() {
// 仅在本地/Web等特殊模式下显示
switch b.filterType {
case FilterLocal:
common.LogBase(i18n.GetText("start_local_scan"))
common.LogInfo(i18n.GetText("start_local_scan"))
case FilterWeb:
common.LogBase(i18n.GetText("start_web_scan"))
common.LogInfo(i18n.GetText("start_web_scan"))
}
}
+4 -4
View File
@@ -137,7 +137,7 @@ func probeWithICMP(hostslist []string, chanHosts chan string, aliveHosts *[]stri
}
common.LogError(i18n.Tr("icmp_listen_failed", err))
common.LogBase(i18n.GetText("trying_no_listen_icmp"))
common.LogInfo(i18n.GetText("trying_no_listen_icmp"))
// 尝试无监听ICMP探测
conn2, err := net.DialTimeout("ip4:icmp", "127.0.0.1", 3*time.Second)
@@ -147,9 +147,9 @@ func probeWithICMP(hostslist []string, chanHosts chan string, aliveHosts *[]stri
return
}
common.LogBase(i18n.Tr("icmp_connect_failed", err))
common.LogBase(i18n.GetText("insufficient_privileges"))
common.LogBase(i18n.GetText("switching_to_ping"))
common.LogError(i18n.Tr("icmp_connect_failed", err))
common.LogError(i18n.GetText("insufficient_privileges"))
common.LogInfo(i18n.GetText("switching_to_ping"))
// 降级使用ping探测
RunPing(hostslist, chanHosts, livewg)
+3 -3
View File
@@ -24,9 +24,9 @@ func NewLocalScanStrategy() *LocalScanStrategy {
func (s *LocalScanStrategy) LogPluginInfo(config *common.Config) {
localPlugin := config.LocalPlugin
if localPlugin != "" {
common.LogBase(i18n.Tr("local_plugin_info", localPlugin))
common.LogInfo(i18n.Tr("local_plugin_info", localPlugin))
} else {
common.LogBase(i18n.GetText("local_plugin_not_specified"))
common.LogError(i18n.GetText("local_plugin_not_specified"))
}
}
@@ -54,7 +54,7 @@ func (s *LocalScanStrategy) Execute(config *common.Config, state *common.State,
// 验证本地插件是否存在
if config.LocalPlugin != "" {
if !plugins.Exists(config.LocalPlugin) {
common.LogBase(i18n.Tr("local_plugin_not_found", config.LocalPlugin))
common.LogError(i18n.Tr("local_plugin_not_found", config.LocalPlugin))
return
}
}
+4 -4
View File
@@ -213,7 +213,7 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo
// 检查代理可靠性,如果存在全回显问题则警告
if common.IsProxyEnabled() && !common.IsProxyReliable() {
common.LogBase("[!] 检测到代理存在全回显问题,端口扫描结果可能不准确")
common.LogError("检测到代理存在全回显问题,端口扫描结果可能不准确")
}
// 创建流式迭代器(O(1) 内存,端口喷洒策略)
@@ -226,12 +226,12 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo
// 大规模扫描警告和线程数自动调整
if totalTasks > 100000 {
common.LogBase(fmt.Sprintf("[*] 大规模扫描: %d 个目标 (%d主机 × %d端口)", totalTasks, len(hosts), len(portList)))
common.LogInfo(fmt.Sprintf("大规模扫描: %d 个目标 (%d主机 × %d端口)", totalTasks, len(hosts), len(portList)))
// 如果任务数超过100万且线程数大于300,自动降低线程数
if totalTasks > 1000000 && threadNum > 300 {
oldThreadNum := threadNum
threadNum = 300
common.LogBase(fmt.Sprintf("[*] 自动调整线程数: %d -> %d (大规模扫描优化)", oldThreadNum, threadNum))
common.LogInfo(fmt.Sprintf("自动调整线程数: %d -> %d (大规模扫描优化)", oldThreadNum, threadNum))
}
}
@@ -285,7 +285,7 @@ func EnhancedPortScan(hosts []string, ports string, timeout int64, config *commo
common.FinishProgressBar()
}
common.LogBase(i18n.Tr("port_scan_complete", count))
common.LogInfo(i18n.Tr("port_scan_complete", count))
// 检查扫描失败率,如果过高则警告用户
resourceErrors := state.GetResourceExhaustedCount()
+6 -6
View File
@@ -96,21 +96,21 @@ func RunScan(info common.HostInfo, config *common.Config, state *common.State) {
// 检查是否有活跃的连接需要维持
if state.IsReverseShellActive() || state.IsSocks5ProxyActive() || state.IsForwardShellActive() {
if state.IsReverseShellActive() {
common.LogBase(i18n.GetText("active_reverse_shell"))
common.LogInfo(i18n.GetText("active_reverse_shell"))
}
if state.IsSocks5ProxyActive() {
common.LogBase(i18n.GetText("active_socks5_proxy"))
common.LogInfo(i18n.GetText("active_socks5_proxy"))
}
if state.IsForwardShellActive() {
common.LogBase(i18n.GetText("active_forward_shell"))
common.LogInfo(i18n.GetText("active_forward_shell"))
}
common.LogBase(i18n.GetText("press_ctrl_c_exit"))
common.LogInfo(i18n.GetText("press_ctrl_c_exit"))
// 优雅等待信号
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
<-sigChan
common.LogBase(i18n.GetText("received_exit_signal"))
common.LogInfo(i18n.GetText("received_exit_signal"))
}
// 完成扫描
@@ -125,7 +125,7 @@ func finishScan(config *common.Config, state *common.State) {
}
// 输出扫描完成信息
common.LogBase(i18n.Tr("scan_task_complete", time.Since(state.GetStartTime()).Round(time.Millisecond), state.GetNum()))
common.LogInfo(i18n.Tr("scan_task_complete", time.Since(state.GetStartTime()).Round(time.Millisecond), state.GetNum()))
// 输出性能统计 JSON(如果启用)
if config.Output.PerfStats {
+7 -7
View File
@@ -70,12 +70,12 @@ func (s *ServiceScanStrategy) showPluginsForSpecifiedPorts(config *common.Config
if len(applicablePlugins) > 0 {
pluginStr := formatPluginList(applicablePlugins)
if isCustomMode {
common.LogBase(i18n.Tr("service_plugin_custom", pluginStr))
common.LogInfo(i18n.Tr("service_plugin_custom", pluginStr))
} else {
common.LogBase(i18n.Tr("service_plugin_info", pluginStr))
common.LogInfo(i18n.Tr("service_plugin_info", pluginStr))
}
} else {
common.LogBase(i18n.GetText("service_plugin_none"))
common.LogInfo(i18n.GetText("service_plugin_none"))
}
}
@@ -201,9 +201,9 @@ func (s *ServiceScanStrategy) LogVulnerabilityPluginInfo(targets []common.HostIn
// 输出插件信息
if len(servicePlugins) > 0 {
common.LogBase(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", ")))
common.LogInfo(i18n.Tr("service_plugin_info", strings.Join(servicePlugins, ", ")))
} else {
common.LogBase(i18n.GetText("scan_no_service_plugins"))
common.LogInfo(i18n.GetText("scan_no_service_plugins"))
}
}
@@ -227,7 +227,7 @@ func (s *ServiceScanStrategy) discoverTargets(hostInput string, baseInfo common.
// 主机存活检测
if s.shouldPerformLivenessCheck(hosts, config) {
hosts = CheckLive(hosts, false, config, state)
common.LogBase(i18n.Tr("alive_hosts_count_info", len(hosts)))
common.LogInfo(i18n.Tr("alive_hosts_count_info", len(hosts)))
}
// 端口扫描
@@ -253,7 +253,7 @@ func (s *ServiceScanStrategy) discoverAlivePorts(hosts []string, config *common.
hostPorts := state.GetHostPorts()
if len(hostPorts) > 0 {
alivePorts = hostPorts
common.LogBase(i18n.Tr("alive_ports_count", len(alivePorts)))
common.LogInfo(i18n.Tr("alive_ports_count", len(alivePorts)))
state.ClearHostPorts()
return alivePorts
}