Skip to content

Commit

Permalink
feat(galois): structured logging (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen authored May 31, 2024
2 parents 3563c07 + c1fc301 commit 4b1bb66
Show file tree
Hide file tree
Showing 25 changed files with 730 additions and 224 deletions.
30 changes: 24 additions & 6 deletions galoisd/cmd/galoisd/cmd/serve.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package cmd

import (
"fmt"
provergrpc "galois/grpc"
provergrpcapi "galois/grpc/api/v3"
"log"
"net"
"os"
"time"

"github.com/consensys/gnark/logger"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/spf13/cobra"
"golang.org/x/net/netutil"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)

const (
flagR1CS = "cs-path"
flagPK = "pk-path"
flagVK = "vk-path"
flagMaxConn = "max-conn"
flagR1CS = "cs-path"
flagPK = "pk-path"
flagVK = "vk-path"
flagMaxConn = "max-conn"
flagLogLevel = "log-level"
)

func ServeCmd() *cobra.Command {
Expand All @@ -42,6 +48,17 @@ func ServeCmd() *cobra.Command {
if err != nil {
return err
}
logLevel, err := cmd.Flags().GetInt(flagLogLevel)
if err != nil {
return err
}
if logLevel > int(zerolog.PanicLevel) || logLevel < int(zerolog.TraceLevel) {
return fmt.Errorf("log level must be between TraceLevel and PanicLevel")
}
zerolog.SetGlobalLevel(zerolog.Level(logLevel))
log.Logger = log.With().Caller().Logger().Output(os.Stdout)
logger.Set(log.Logger)

server, err := provergrpc.NewProverServer(uint32(maxConn), r1csPath, pkPath, vkPath)
if err != nil {
return err
Expand All @@ -60,13 +77,14 @@ func ServeCmd() *cobra.Command {
Timeout: 20 * time.Second,
}))
provergrpcapi.RegisterUnionProverAPIServer(grpcServer, server)
log.Println("Serving...")
log.Info().Msg("Serving...")
return grpcServer.Serve(limitedLis)
},
}
cmd.Flags().String(flagR1CS, "r1cs.bin", "Path to the compiled R1CS circuit.")
cmd.Flags().String(flagPK, "pk.bin", "Path to the proving key.")
cmd.Flags().String(flagVK, "vk.bin", "Path to the verifying key.")
cmd.Flags().Int(flagMaxConn, 1, "Maximum number of concurrent connection.")
cmd.Flags().Int(flagLogLevel, int(zerolog.InfoLevel), "Log level see https://github.com/rs/zerolog/blob/c78e50e2da70f4ae63e1b65222c3acf12e9ba699/README.md#leveled-logging")
return cmd
}
2 changes: 1 addition & 1 deletion galoisd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/consensys/gnark v0.7.2-0.20230418172633-f83323bdf138
github.com/consensys/gnark-crypto v0.12.2-0.20240215234832-d72fcb379d3e
github.com/cosmos/cosmos-sdk v0.50.2
github.com/rs/zerolog v1.31.0
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
golang.org/x/net v0.19.0
Expand Down
4 changes: 2 additions & 2 deletions galoisd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo=
github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0=
Expand Down
Loading

0 comments on commit 4b1bb66

Please sign in to comment.