Skip to content

Commit 0867077

Browse files
committed
cli: add --log-level option
also use standard logger for audit so it honors this parameter Signed-off-by: Javi Fontan <[email protected]>
1 parent 115a755 commit 0867077

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cmd/gitbase/command/server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Server struct {
6262
DisableGit bool `long:"no-git" description:"disable the load of git standard repositories."`
6363
DisableSiva bool `long:"no-siva" description:"disable the load of siva files."`
6464
Verbose bool `short:"v" description:"Activates the verbose mode"`
65+
LogLevel string `long:"log-level" env:"GITBASE_LOG_LEVEL" choice:"info" choice:"debug" choice:"warning" choice:"error" choice:"fatal" default:"info" description:"logging level"`
6566
}
6667

6768
type jaegerLogrus struct {
@@ -107,6 +108,12 @@ func NewDatabaseEngine(
107108
func (c *Server) Execute(args []string) error {
108109
if c.Verbose {
109110
logrus.SetLevel(logrus.DebugLevel)
111+
} else {
112+
level, err := logrus.ParseLevel(c.LogLevel)
113+
if err != nil {
114+
return fmt.Errorf("cannot parse log level: %s", err.Error())
115+
}
116+
logrus.SetLevel(level)
110117
}
111118

112119
var err error
@@ -127,7 +134,7 @@ func (c *Server) Execute(args []string) error {
127134
c.userAuth = auth.NewNativeSingle(c.User, c.Password, permissions)
128135
}
129136

130-
c.userAuth = auth.NewAudit(c.userAuth, auth.NewAuditLog(logrus.New()))
137+
c.userAuth = auth.NewAudit(c.userAuth, auth.NewAuditLog(logrus.StandardLogger()))
131138
if err := c.buildDatabase(); err != nil {
132139
logrus.WithField("error", err).Fatal("unable to initialize database engine")
133140
return err

0 commit comments

Comments
 (0)