feat: add download logs functionality and update log file size limit

This commit is contained in:
SunBK201 2025-11-03 16:03:17 +08:00
parent 98969cee5e
commit f1f93c073a
6 changed files with 50 additions and 6 deletions

View File

@ -7,5 +7,5 @@ License: GPL-3.0-only
Section: net
SourceDateEpoch: 1711267200
Architecture: all
Installed-Size: 4495360
Installed-Size: 4505600
Description: Advanced HTTP User-Agent Rewriting Tool.

View File

@ -7,5 +7,5 @@ License: GPL-3.0-only
Section: net
SourceDateEpoch: 1711267200
Architecture: all
Installed-Size: 4495360
Installed-Size: 4505600
Description: Advanced HTTP User-Agent Rewriting Tool.

View File

@ -97,6 +97,13 @@ logLines.default = "1000"
logLines.datatype = "uinteger"
logLines.rmempty = false
download = general:taboption("log", Button, "_download", translate("Download Logs"))
download.inputtitle = translate("Download Logs")
download.inputstyle = "apply"
function download.write(self, section)
luci.http.redirect(luci.dispatcher.build_url("admin/services/ua3f/download_log"))
end
stats = general:taboption("stats", DummyValue, "")
stats.template = "ua3f/statistics"

View File

@ -2,4 +2,38 @@ module("luci.controller.ua3f", package.seeall)
function index()
entry({ "admin", "services", "ua3f" }, cbi("ua3f"), _("UA3F"), 1)
entry({ "admin", "services", "ua3f", "download_log" }, call("action_download_log"), _("Download Logs"), 11).leaf = true
end
function action_download_log()
local nixio = require "nixio"
local fs = require "nixio.fs"
local http = require "luci.http"
local tmpfile = "/tmp/ua3f_logs.tar.gz"
local cmd = "cd /var/log && tar -czf " .. tmpfile .. " ua3f >/dev/null 2>&1"
os.execute(cmd)
if not fs.access(tmpfile) then
http.status(500, "Internal Server Error")
http.prepare_content("text/plain")
http.write("Failed to create archive")
return
end
http.header("Content-Type", "application/gzip")
http.header("Content-Disposition", 'attachment; filename="ua3f_logs.tar.gz"')
http.header("Content-Length", tostring(fs.stat(tmpfile).size))
local fp = io.open(tmpfile, "rb")
if fp then
while true do
local chunk = fp:read(2048)
if not chunk then break end
http.write(chunk)
end
fp:close()
end
nixio.fs.remove(tmpfile)
end

View File

@ -82,3 +82,6 @@ msgstr "显示行数"
msgid "Sets the logging level. Do not keep the log level set to debug/info/warn for an extended period of time."
msgstr "设置日志级别,请勿长时间将日志级别设置为 debug / info / warn"
msgid "Download Logs"
msgstr "下载日志"

View File

@ -39,7 +39,7 @@ func SetLogConf(level string) {
writer2 := os.Stdout
writer3 := &lumberjack.Logger{
Filename: log_file,
MaxSize: 2, // megabytes
MaxSize: 5, // megabytes
MaxBackups: 5,
MaxAge: 7, //days
LocalTime: true,