Merge pull request #605 from sosedoff/log-level

Configure logging level and format
This commit is contained in:
Dan Sosedoff
2022-12-06 12:41:56 -06:00
committed by GitHub
5 changed files with 41 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/jessevdk/go-flags"
"github.com/sirupsen/logrus"
)
const (
@@ -18,6 +19,8 @@ const (
type Options struct {
Version bool `short:"v" long:"version" description:"Print version"`
Debug bool `short:"d" long:"debug" description:"Enable debugging mode"`
LogLevel string `long:"log-level" description:"Logging level" default:"info"`
LogFormat string `long:"log-format" description:"Logging output format" default:"text"`
URL string `long:"url" description:"Database connection string"`
Host string `long:"host" description:"Server hostname or IP" default:"localhost"`
Port int `long:"port" description:"Server port" default:"5432"`
@@ -62,6 +65,11 @@ func ParseOptions(args []string) (Options, error) {
return opts, err
}
_, err = logrus.ParseLevel(opts.LogLevel)
if err != nil {
return opts, err
}
if opts.URL == "" {
opts.URL = getPrefixedEnvVar("DATABASE_URL")
}