feat: enhance logging for firewall setup and system info

This commit is contained in:
SunBK201 2025-11-21 00:25:54 +08:00
parent bc94b341c0
commit a3cd2cbef8
3 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"io"
"log/slog"
"os"
"runtime"
"strings"
"time"
@ -57,6 +58,7 @@ func SetLogConf(level string) {
func LogHeader(version string, cfg *config.Config) {
slog.Info("UA3F started", "version", version, "", cfg)
slog.Info("System Info", slog.String("Go Version", strings.TrimPrefix(strings.TrimSpace(runtime.Version()), "go")), slog.String("OS/Arch", runtime.GOOS+"/"+runtime.GOARCH))
}
func LogDebugWithAddr(src string, dest string, msg string) {

View File

@ -108,6 +108,7 @@ type Firewall struct {
func (f *Firewall) Setup(cfg *config.Config) (err error) {
_ = f.Cleanup()
backend := detectFirewallBackend(cfg)
slog.Info("Setup firewall", slog.String("backend", backend))
switch backend {
case NFT:
if f.NftSetup == nil {
@ -125,6 +126,8 @@ func (f *Firewall) Setup(cfg *config.Config) (err error) {
if err != nil {
_ = f.Cleanup()
}
f.DumpNFTables()
f.DumpIPTables()
return err
}
@ -144,7 +147,7 @@ func (f *Firewall) DumpNFTables() {
if err != nil {
return
}
slog.Debug(fmt.Sprintf("nftables ruleset:\n%s", string(output)))
slog.Info("nftables ruleset:\n" + string(output))
}
func (f *Firewall) DumpIPTables() {

View File

@ -45,8 +45,6 @@ func (s *Server) Start() (err error) {
slog.Error("Firewall.Setup", slog.Any("error", err))
return err
}
s.Firewall.DumpNFTables()
s.Firewall.DumpIPTables()
if s.cfg.SetTTL || s.cfg.DelTCPTimestamp || s.cfg.SetIPID {
slog.Info("Packet modification features enabled")
go s.nfqServer.Start()