Skip to content

Commit

Permalink
feat: added logorus as logging library
Browse files Browse the repository at this point in the history
closes #9
  • Loading branch information
Gurkengewuerz committed Oct 25, 2024
1 parent 3c45959 commit 8787752
Show file tree
Hide file tree
Showing 18 changed files with 1,545 additions and 146 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ docker-compose up -d
|----------------------------|-----------------------------------------|---------------------------------------------------|----------|
| **Server Configuration** |
| `SERVER_ADDRESS` | Judge server address | `:3000` | No |
| `LOG_LEVEL` | Log level from 0-6. 4 being Info | `4` | No |
| `MAX_PARALLEL_JUDGES` | Maximum parallel executions | `5` | No |
| `TESTS_PATH` | Path to test cases directory | `test_cases` | No |
| **Database Configuration** |
Expand Down
18 changes: 13 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@ import (
"github.com/gurkengewuerz/GitCodeJudge/internal/api"
"github.com/gurkengewuerz/GitCodeJudge/internal/judge"
"github.com/gurkengewuerz/GitCodeJudge/internal/judge/scoreboard"
"log"
log "github.com/sirupsen/logrus"
"os"
"os/signal"
"syscall"
)

func main() {
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
FullTimestamp: true,
})
log.SetLevel(log.InfoLevel)

cfg, err := config.Load()
if err != nil {
log.Fatalf("Failed to load config: %v", err)
log.WithError(err).Fatal("Failed to load config")
}

log.SetLevel(log.Level(cfg.LogLevel))

err = db.Load(cfg)
if err != nil {
log.Fatalf("Failed to load db: %v", err)
log.WithError(err).Fatal("Failed to load db")
}
defer db.DB.Close()

Expand All @@ -45,7 +53,7 @@ func main() {
// Start server
go func() {
if err := router.Listen(cfg.ServerAddress); err != nil {
log.Fatalf("Failed to start server: %v", err)
log.WithError(err).Fatalf("Failed to start server")
}
}()

Expand All @@ -54,5 +62,5 @@ func main() {
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit

log.Println("Shutting down server...")
log.Info("Shutting down server...")
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type Config struct {
// Server configuration
ServerAddress string `envconfig:"SERVER_ADDRESS" default:":3000"`
LogLevel int `envconfig:"LOG_LEVEL" default:"4"`
MaxParallelJudges int `envconfig:"MAX_PARALLEL_JUDGES" default:"5"`
TestPath string `envconfig:"TESTS_PATH" default:"test_cases"`

Expand Down
7 changes: 3 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"github.com/dgraph-io/badger/v4"
"github.com/gurkengewuerz/GitCodeJudge/config"
"log"
log "github.com/sirupsen/logrus"
"time"
)

Expand All @@ -13,8 +13,7 @@ var DB *badger.DB
func Load(cfg *config.Config) error {
// It will be created if it doesn't exist.
options := badger.DefaultOptions(cfg.DatabasePath)
// TODO Set to new logging library
// options.Logger = nil
options.Logger = log.StandardLogger()

db, err := badger.Open(options)
if err != nil {
Expand Down Expand Up @@ -58,5 +57,5 @@ func StartValueLogGC(ctx context.Context) func() {
func runGC(db *badger.DB) {
// RunValueLogGC returns error when there's nothing to clean
_ = db.RunValueLogGC(0.5)
log.Printf("Ran Datbase GC")
log.Debug("Ran Datbase GC")
}
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ module github.com/gurkengewuerz/GitCodeJudge
go 1.23.1

require (
github.com/dgraph-io/badger/v4 v4.3.1
github.com/docker/docker v27.3.1+incompatible
github.com/go-git/go-git/v5 v5.12.0
github.com/gofiber/fiber/v3 v3.0.0-beta.3
github.com/johnfercher/maroto/v2 v2.2.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/sirupsen/logrus v1.9.3
github.com/yuin/goldmark v1.7.8
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -21,7 +25,6 @@ require (
github.com/containerd/log v0.1.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/badger/v4 v4.3.1 // indirect
github.com/dgraph-io/ristretto v1.0.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-connections v0.5.0 // indirect
Expand All @@ -34,7 +37,6 @@ require (
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gofiber/fiber/v3 v3.0.0-beta.3 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.7 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down Expand Up @@ -67,7 +69,6 @@ require (
github.com/valyala/fasthttp v1.56.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/yuin/goldmark v1.7.8 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
Expand All @@ -84,8 +85,12 @@ require (
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
)

replace google.golang.org/grpc => google.golang.org/grpc v1.56.3
Loading

0 comments on commit 8787752

Please sign in to comment.