修复Log文件输出不可用的问题

This commit is contained in:
WindyMadman 2024-08-31 16:17:19 +08:00
parent c858ede656
commit e68b13e290
2 changed files with 11 additions and 14 deletions

View File

@ -39,18 +39,15 @@ end
-- 是否启用日志
o = s:taboption("general", Flag, "enable_logging", translate("Enable logging"))
o.enabled = "true"
o.disabled = "false"
o.default = o.enabled
-- 日志路径
o = s:taboption("general", Value, "log_to", translate("Log file"))
o:depends("enable_logging", "true")
o:depends("enable_logging", "1")
o.default = "/var/log/frps.log"
-- 日志等级
o = s:taboption("general", ListValue, "log_level", translate("Log level"))
o:depends("enable_logging", "true")
o:depends("enable_logging", "1")
o:value("trace", translate("Trace"))
o:value("debug", translate("Debug"))
o:value("info", translate("Info"))
@ -61,7 +58,7 @@ o.default = "Warn"
-- 日志保留天数
o = s:taboption("general", ListValue, "log_maxdays", translate("Log max days"))
o.description = translate("Maximum number of days to keep log files is 3 day.")
o:depends("enable_logging", "true")
o:depends("enable_logging", "1")
o.datatype = "uinteger"
o:value("1", translate("1"))
o:value("2", translate("2"))

View File

@ -73,7 +73,7 @@ append_options() {
;;
"enable_prometheus")
echo "enablePrometheus = $v" >>"$file"
;;
;;
"webserver_addr")
echo "webServer.addr = \"$v\"" >>"$file"
;;
@ -168,17 +168,17 @@ create_config_file() {
if [ "x$enable_logging" = "x1" ] ; then
if [ -z "$log_file" ]; then
log_file="/var/log/frps.log"
if [ -z "$log_to" ]; then
log_to="/var/log/frps.log"
fi
append_options "$tmp_file" \
"log_to" "log_level" "log_maxdays" "log_disable_print_color"
if [ -f "$log_file" ] ; then
echo > "$log_file"
if [ -f "$log_to" ] ; then
echo > "$log_to"
else
local log_folder="$(dirname "$log_file")"
local log_folder="$(dirname "$log_to")"
if [ ! -d "$log_folder" ] ; then
mkdir -p "$log_folder"
@ -186,8 +186,8 @@ create_config_file() {
fi
if [ -n "$run_user" ] && ( user_exists "$run_user" ) ; then
chmod 644 "$log_file"
chown "$run_user" "$log_file"
chmod 644 "$log_to"
chown "$run_user" "$log_to"
else
run_user=""
fi