feat: set gin log writer

This commit is contained in:
Noah Hsu 2022-06-06 22:06:33 +08:00
parent fced60c2b5
commit 09616dbe25
5 changed files with 31 additions and 11 deletions

View File

@ -1,3 +0,0 @@
What to do at startup, such as:
- parse config
- init store

View File

@ -4,16 +4,18 @@ import (
"github.com/alist-org/alist/v3/cmd/args"
"github.com/alist-org/alist/v3/conf"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"log"
"time"
)
func Log() {
log.SetOutput(logrus.StandardLogger().Out)
if args.Debug {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
}
log.SetFormatter(&log.TextFormatter{
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
EnvironmentOverrideColors: true,
TimestampFormat: "2006-01-02 15:04:05",
@ -40,9 +42,9 @@ func Log() {
)
}
if err != nil {
log.Fatalf("failed to create rotate log: %s", err)
logrus.Fatalf("failed to create rotate logrus: %s", err)
}
log.SetOutput(writer)
logrus.SetOutput(writer)
}
log.Infof("init log...")
logrus.Infof("init logrus...")
}

View File

@ -6,6 +6,8 @@ import (
"github.com/alist-org/alist/v3/bootstrap"
"github.com/alist-org/alist/v3/cmd/args"
"github.com/alist-org/alist/v3/conf"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"os"
)
@ -29,4 +31,21 @@ func Init() {
}
func main() {
Init()
if !args.Debug {
gin.SetMode(gin.ReleaseMode)
}
r := gin.New()
r.Use(gin.LoggerWithWriter(log.StandardLogger().Out), gin.RecoveryWithWriter(log.StandardLogger().Out))
// TODO: setup router
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
log.Infof("start server @ %s", base)
var err error
if conf.Conf.Scheme.Https {
err = r.RunTLS(base, conf.Conf.Scheme.CertFile, conf.Conf.Scheme.KeyFile)
} else {
err = r.Run(base)
}
if err != nil {
log.Errorf("failed to start: %s", err.Error())
}
}

1
drivers/local/driver.go Normal file
View File

@ -0,0 +1 @@
package local

View File

@ -4,6 +4,7 @@ type Account struct {
ID uint `json:"id" gorm:"primaryKey"`
VirtualPath string `json:"virtual_path"`
Index int `json:"index"`
Type string `json:"type"`
Driver string `json:"driver"`
Status string `json:"status"`
Custom string `json:"custom"`
}