Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2022-03-21 06:42:08 +0300
committerJames Fargher <jfargher@gitlab.com>2022-03-31 01:27:17 +0300
commit2606b45695ab42235cb2a56cfd957b7d24d209d7 (patch)
treea44b22f919d338056490f7d45de496ca4ea8ced3
parent164e7259d7febd5f1a58b1b537739aa26e9be3f2 (diff)
gitaly-git2go: Add flags to configure log level and format
The usage of FlagSet here was incorrect as the parser is not expecting the binary name in the list. Configure logging to output to stderr so it will not interfere with gob encoding on stdout.
-rw-r--r--cmd/gitaly-git2go-v14/main.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/cmd/gitaly-git2go-v14/main.go b/cmd/gitaly-git2go-v14/main.go
index 1bbdf6e20..39cb817cc 100644
--- a/cmd/gitaly-git2go-v14/main.go
+++ b/cmd/gitaly-git2go-v14/main.go
@@ -12,6 +12,7 @@ import (
git "github.com/libgit2/git2go/v33"
"gitlab.com/gitlab-org/gitaly/v14/internal/git2go"
+ glog "gitlab.com/gitlab-org/gitaly/v14/internal/log"
)
type subcmd interface {
@@ -43,27 +44,39 @@ func fatalf(encoder *gob.Encoder, format string, args ...interface{}) {
os.Exit(0)
}
+func configureLogging(format, level string) {
+ // Gitaly logging by default goes to stdout, which would interfere with gob
+ // encoding.
+ for _, l := range glog.Loggers {
+ l.Out = os.Stderr
+ }
+ glog.Configure(glog.Loggers, format, level)
+}
+
func main() {
decoder := gob.NewDecoder(os.Stdin)
encoder := gob.NewEncoder(os.Stdout)
- flags := flag.NewFlagSet(git2go.BinaryName, flag.ContinueOnError)
+ var logFormat, logLevel string
- if err := flags.Parse(os.Args); err != nil {
- fatalf(encoder, "parsing flags: %s", err)
- }
+ flags := flag.NewFlagSet(git2go.BinaryName, flag.PanicOnError)
+ flags.StringVar(&logFormat, "log-format", "", "logging format")
+ flags.StringVar(&logLevel, "log-level", "", "logging level")
+ _ = flags.Parse(os.Args[1:])
+
+ configureLogging(logFormat, logLevel)
- if flags.NArg() < 2 {
+ if flags.NArg() < 1 {
fatalf(encoder, "missing subcommand")
}
- subcmd, ok := subcommands[flags.Arg(1)]
+ subcmd, ok := subcommands[flags.Arg(0)]
if !ok {
fatalf(encoder, "unknown subcommand: %q", flags.Arg(0))
}
subcmdFlags := subcmd.Flags()
- if err := subcmdFlags.Parse(flags.Args()[2:]); err != nil {
+ if err := subcmdFlags.Parse(flags.Args()[1:]); err != nil {
fatalf(encoder, "parsing flags of %q: %s", subcmdFlags.Name(), err)
}