mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-16 08:44:29 +00:00
refactor: refactor logging setup and directory structure for ua3f service
This commit is contained in:
parent
a51522aff4
commit
c29f0b2cd7
@ -31,7 +31,7 @@ ck_ua3f_log() {
|
||||
if [ -f "/var/log/ua3f.log" ]; then
|
||||
rm "/var/log/ua3f.log"
|
||||
fi
|
||||
touch /var/log/ua3f.log && chmod 666 /var/log/ua3f.log
|
||||
mkdir -p /var/log/ua3f && chmod ugo+w /var/log/ua3f
|
||||
}
|
||||
|
||||
dl_ua3f() {
|
||||
|
||||
@ -44,7 +44,7 @@ log_level:value("panic")
|
||||
log = main:taboption("log", TextValue, "")
|
||||
log.readonly = true
|
||||
log.cfgvalue = function(self, section)
|
||||
return luci.sys.exec("cat /var/log/ua3f.log")
|
||||
return luci.sys.exec("cat /var/log/ua3f/ua3f.log")
|
||||
end
|
||||
log.rows = 30
|
||||
|
||||
|
||||
@ -29,7 +29,8 @@ start_service() {
|
||||
config_get_bool partial_replace "main" "partial_replace" 0
|
||||
config_get log_level "main" "log_level" "info"
|
||||
|
||||
chmod o+w /var/log
|
||||
mkdir -p /var/log/ua3f
|
||||
chmod o+w /var/log/ua3f
|
||||
|
||||
procd_open_instance "$NAME"
|
||||
procd_set_param command "$PROG"
|
||||
|
||||
@ -29,7 +29,8 @@ start_service() {
|
||||
config_get_bool partial_replace "main" "partial_replace" 0
|
||||
config_get log_level "main" "log_level" "info"
|
||||
|
||||
chmod o+w /var/log
|
||||
mkdir -p /var/log/ua3f
|
||||
chmod o+w /var/log/ua3f
|
||||
|
||||
procd_open_instance "$NAME"
|
||||
procd_set_param command "$PROG"
|
||||
|
||||
@ -44,7 +44,7 @@ log_level:value("panic")
|
||||
log = main:taboption("log", TextValue, "")
|
||||
log.readonly = true
|
||||
log.cfgvalue = function(self, section)
|
||||
return luci.sys.exec("cat /var/log/ua3f.log")
|
||||
return luci.sys.exec("cat /var/log/ua3f/ua3f.log")
|
||||
end
|
||||
log.rows = 30
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ require (
|
||||
github.com/dlclark/regexp2 v1.11.4
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -21,6 +21,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -4,11 +4,11 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
type uctFormatter struct {
|
||||
@ -27,11 +27,16 @@ func (formatter *uctFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
}
|
||||
|
||||
func SetLogConf(level string) {
|
||||
log_file := "/var/log/ua3f/ua3f.log"
|
||||
writer1 := &bytes.Buffer{}
|
||||
writer2 := os.Stdout
|
||||
writer3, err := os.OpenFile("/var/log/ua3f.log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
|
||||
if err != nil {
|
||||
log.Fatalf("create file ua3f.log failed: %v", err)
|
||||
writer3 := &lumberjack.Logger{
|
||||
Filename: log_file,
|
||||
MaxSize: 2, // megabytes
|
||||
MaxBackups: 3,
|
||||
MaxAge: 28, //days
|
||||
LocalTime: true,
|
||||
Compress: true,
|
||||
}
|
||||
logrus.SetOutput(io.MultiWriter(writer1, writer2, writer3))
|
||||
formatter := &uctFormatter{}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user