Skip to content

Commit

Permalink
Use vertex-logger (vlog) package
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinguidee committed Sep 9, 2023
1 parent 3cf8523 commit 36ed0d7
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 413 deletions.
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ require (
github.com/disgoorg/disgo v0.16.9
github.com/docker/docker v23.0.3+incompatible
github.com/docker/go-connections v0.4.0
github.com/fatih/color v1.14.1
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/sse v0.1.0
github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.9.0
github.com/go-co-op/gocron v1.23.0
github.com/go-co-op/gocron v1.33.1
github.com/go-git/go-git/v5 v5.6.1
github.com/google/go-github/v50 v50.0.0
github.com/google/uuid v1.3.0
github.com/google/uuid v1.3.1
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/vertex-center/vertex-core-golang v0.0.0-20230423023245-a01db2466031
github.com/vertex-center/vlog v1.0.1
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -38,6 +38,7 @@ require (
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand Down Expand Up @@ -77,6 +78,7 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/arch v0.1.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.11.0 // indirect
Expand Down
22 changes: 14 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand All @@ -61,8 +61,8 @@ github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8=
github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/go-co-op/gocron v1.23.0 h1:cD8PCSsa88HKJSC8XhSWATSEKdgfKjrlnDu8zX+Jce4=
github.com/go-co-op/gocron v1.23.0/go.mod h1:gEQbrsoOV+HAp59D3LmYFgENQDeYp2QHsHT8N/Wzs/U=
github.com/go-co-op/gocron v1.33.1 h1:wjX+Dg6Ae29a/f9BSQjY1Rl+jflTpW9aDyMqseCj78c=
github.com/go-co-op/gocron v1.33.1/go.mod h1:NLi+bkm4rRSy1F8U7iacZOz0xPseMoIOnvabGoSe/no=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
Expand Down Expand Up @@ -105,8 +105,8 @@ github.com/google/go-github/v50 v50.0.0/go.mod h1:Ev4Tre8QoKiolvbpOSG3FIi4Mlon3S
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
Expand Down Expand Up @@ -178,8 +178,9 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
Expand All @@ -201,8 +202,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
Expand All @@ -213,11 +215,15 @@ github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU
github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vertex-center/vertex-core-golang v0.0.0-20230423023245-a01db2466031 h1:og0cF2u0K3n9628dEwi6QM5u5AcPwO4XKgp9ndHlfb0=
github.com/vertex-center/vertex-core-golang v0.0.0-20230423023245-a01db2466031/go.mod h1:LW8yo6JkIKZxVJKhgbLsf1CAocMWnDYz1luF04juh/g=
github.com/vertex-center/vlog v1.0.1 h1:fa2bBD1h4T3+KNQ5jphuQ/Fb9eRj1uC28n/xYBFubRw=
github.com/vertex-center/vlog v1.0.1/go.mod h1:M52swDkdWWu3VWY2Cj+mqc64Nzx33sDukAgrQ3HA95c=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.1.0 h1:oMxhUYsO9VsR1dcoVUjJjIGhx1LXol3989T/yZ59Xsw=
golang.org/x/arch v0.1.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
Expand Down
20 changes: 10 additions & 10 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"runtime"

"github.com/vertex-center/vertex/config"
"github.com/vertex-center/vertex/pkg/logger"
"github.com/vertex-center/vertex/pkg/log"
"github.com/vertex-center/vertex/router"
"github.com/vertex-center/vertex/services"
"github.com/vertex-center/vertex/types"
"github.com/vertex-center/vlog"
)

// version, commit and date will be overridden by goreleaser
Expand All @@ -22,22 +23,21 @@ var (
)

func main() {
logger.CreateDefaultLogger()
defer logger.DefaultLogger.CloseLogFiles()
defer log.Default.Close()

logger.Log("Vertex starting...").Print()
log.Default.Info("Vertex starting...")

parseArgs()

err := setupDependencies()
if err != nil {
logger.Error(fmt.Errorf("failed to setup dependencies: %v", err)).Print()
log.Default.Error(fmt.Errorf("failed to setup dependencies: %v", err))
return
}

err = config.Current.Apply()
if err != nil {
logger.Error(fmt.Errorf("failed to apply the current configuration: %v", err)).Print()
log.Default.Error(fmt.Errorf("failed to apply the current configuration: %v", err))
return
}

Expand All @@ -54,9 +54,9 @@ func main() {
// Logs
url := fmt.Sprintf("http://%s", config.Current.Host)
fmt.Printf("\n-- Vertex Client :: %s\n\n", url)
logger.Log("Vertex started").
AddKeyValue("url", url).
Print()
log.Default.Info("Vertex started",
vlog.String("url", url),
)

router.Start(fmt.Sprintf(":%s", config.Current.Port))
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func setupDependencies() error {
for _, dep := range dependencies {
err := setupDependency(dep)
if err != nil {
logger.Error(err).Print()
log.Default.Error(err)
os.Exit(1)
}
}
Expand Down
40 changes: 23 additions & 17 deletions pkg/ginutils/logger.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
package ginutils

import (
"strings"

"github.com/gin-gonic/gin"
"github.com/vertex-center/vertex/pkg/logger"
"github.com/vertex-center/vertex/pkg/log"
"github.com/vertex-center/vlog"
)

func Logger(router string) gin.HandlerFunc {
return gin.LoggerWithFormatter(func(params gin.LogFormatterParams) string {
l := logger.Request().
AddKeyValue("router", router).
AddKeyValue("method", params.Method).
AddKeyValue("status", params.StatusCode).
AddKeyValue("path", params.Path).
AddKeyValue("latency", params.Latency).
AddKeyValue("ip", params.ClientIP).
AddKeyValue("size", params.BodySize)

if params.ErrorMessage != "" {
err, _ := strings.CutSuffix(params.ErrorMessage, "\n")
l.AddKeyValue("error", err)
log.Default.Request("request",
vlog.String("router", router),
vlog.String("method", params.Method),
vlog.Int("status", params.StatusCode),
vlog.String("path", params.Path),
vlog.String("latency", params.Latency.String()),
vlog.String("ip", params.ClientIP),
vlog.Int("size", params.BodySize),
vlog.String("error", params.ErrorMessage),
)
} else {
log.Default.Request("request",
vlog.String("router", router),
vlog.String("method", params.Method),
vlog.Int("status", params.StatusCode),
vlog.String("path", params.Path),
vlog.String("latency", params.Latency.String()),
vlog.String("ip", params.ClientIP),
vlog.Int("size", params.BodySize),
)
}

l.PrintInExternalFiles()

return l.String()
return ""
})
}
9 changes: 9 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package log

import "github.com/vertex-center/vlog"

var Default = *vlog.New(
vlog.WithOutputStd(),
vlog.WithOutputFile("live/logs", vlog.LogFormatText),
vlog.WithOutputFile("live/logs", vlog.LogFormatJson),
)
Loading

0 comments on commit 36ed0d7

Please sign in to comment.