File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -23,16 +23,30 @@ import (
2323 "github.com/patrickmn/go-cache"
2424 log "github.com/sirupsen/logrus"
2525 "golang.org/x/oauth2"
26+ lumberjack "gopkg.in/natefinch/lumberjack.v2"
2627)
2728
2829var (
2930 cacheDb = cache .New (60 * time .Minute , 10 * time .Minute )
3031)
3132
3233func init () {
34+ sn := os .Getenv ("SERVICE_NAME" )
35+ if sn == "" {
36+ sn = "nettica-api"
37+ }
38+ filename := "/var/log/nettica/" + sn + ".log"
39+ lumberjackWriter := & lumberjack.Logger {
40+ Filename : filename ,
41+ MaxSize : 50 , // megabytes
42+ MaxBackups : 10 ,
43+ MaxAge : 30 , // days
44+ Compress : true ,
45+ }
46+
3347 log .SetFormatter (& log.TextFormatter {})
34- log .SetOutput (os .Stderr )
3548 log .SetLevel (log .DebugLevel )
49+ log .SetOutput (io .MultiWriter (os .Stderr , lumberjackWriter ))
3650}
3751
3852// @title Nettica API
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ require (
2525 golang.org/x/oauth2 v0.30.0
2626 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
2727 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
28+ gopkg.in/natefinch/lumberjack.v2 v2.2.1
2829)
2930
3031require (
Original file line number Diff line number Diff line change @@ -386,6 +386,8 @@ gopkg.in/dnaeon/go-vcr.v3 v3.2.0 h1:Rltp0Vf+Aq0u4rQXgmXgtgoRDStTnFN83cWgSGSoRzM=
386386gopkg.in/dnaeon/go-vcr.v3 v3.2.0 /go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag =
387387gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE =
388388gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df /go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw =
389+ gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc =
390+ gopkg.in/natefinch/lumberjack.v2 v2.2.1 /go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc =
389391gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
390392gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
391393gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
You can’t perform that action at this time.
0 commit comments