Skip to content

Commit

Permalink
feat: set gin log writer
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 6, 2022
1 parent fced60c commit 09616db
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
3 changes: 0 additions & 3 deletions bootstrap/README.md

This file was deleted.

16 changes: 9 additions & 7 deletions bootstrap/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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...")
}
19 changes: 19 additions & 0 deletions cmd/alist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 change: 1 addition & 0 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package local
3 changes: 2 additions & 1 deletion internal/model/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 09616db

Please sign in to comment.