diff --git a/.dockerignore b/.dockerignore index 3592d05..9b88ba9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ -.db -.log +.git +*.db +*.log redis Dockerfile docker-compose.yml diff --git a/go.mod b/go.mod index d1e1af9..28b53fa 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,8 @@ replace internal/cache => ./internal/cache require ( github.com/glebarez/sqlite v1.10.0 + github.com/sirupsen/logrus v1.9.3 + gopkg.in/natefinch/lumberjack.v2 v2.2.1 internal/session v1.0.0 ) @@ -41,7 +43,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.3.0 // indirect diff --git a/go.sum b/go.sum index d572194..56a3242 100644 --- a/go.sum +++ b/go.sum @@ -107,6 +107,8 @@ google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cn google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 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= diff --git a/main.go b/main.go index a0288a4..839baf1 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/gin-gonic/gin" _ "github.com/gorilla/sessions" "github.com/sirupsen/logrus" + "gopkg.in/natefinch/lumberjack.v2" "html/template" "io" "os" @@ -16,11 +17,14 @@ import ( ) func init() { - f, err := os.OpenFile("isc_rest.log", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660) - if err != nil { - utils.Logger.Fatalf("[MAIN] Error opening log file: %v", err) + fileLogger := &lumberjack.Logger{ + Filename: "isc_rest.log", + MaxSize: 50, // megabytes + MaxBackups: 3, + MaxAge: 28, //days + Compress: true, } - ginWriter := io.MultiWriter(f, os.Stdout) + ginWriter := io.MultiWriter(fileLogger, os.Stdout) logger := logrus.New() logger.SetOutput(ginWriter) logger.SetFormatter(&logrus.TextFormatter{ @@ -29,6 +33,7 @@ func init() { }) utils.Logger = logger + var err error utils.MainPageTemplates, err = template.ParseFiles( "./templates/index.html", "./templates/components/home_clan_bar.html",