Skip to content

Commit

Permalink
changed "format" to "log-format", config struct
Browse files Browse the repository at this point in the history
Signed-off-by: Moe Ghanem <[email protected]>
  • Loading branch information
Moe Ghanem committed Apr 27, 2023
1 parent 543a021 commit 603472b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 109 deletions.
4 changes: 2 additions & 2 deletions cmd/buildctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
},
// Add format flag to control log formatter
cli.StringFlag{
Name: "format",
Name: "log-format",
Usage: "log formatter: json or text",
Value: "text",
},
Expand Down Expand Up @@ -109,7 +109,7 @@ func main() {
app.Before = func(context *cli.Context) error {
debugEnabled = context.GlobalBool("debug")
// Use Format flag to control log formatter
logFormat = context.GlobalString("format")
logFormat = context.GlobalString("log-format")
if logFormat == "json" {
logrus.SetFormatter(&logrus.JSONFormatter{})
} else {
Expand Down
3 changes: 3 additions & 0 deletions cmd/buildkitd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Config struct {
DNS *DNSConfig `toml:"dns"`

History *HistoryConfig `toml:"history"`

// LogFormat is the format of the logs. It can be "json" or "text".
LogFormat string `toml:"log-format"`
}

type GRPCConfig struct {
Expand Down
26 changes: 8 additions & 18 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ func init() {
detect.Recorder = detect.NewTraceRecorder()
}

// TOML STRUCTUTRE
// [app]
// format = "json"
type Config struct {
App struct {
Format string `toml:"format"`
} `toml:"app"`
}

var propagators = propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})

type workerInitializerOpt struct {
Expand Down Expand Up @@ -179,7 +170,7 @@ func main() {
},
// Add format flag to control log formatter
cli.StringFlag{
Name: "format",
Name: "log-format",
Usage: "log formatter: json or text",
Value: "text",
},
Expand Down Expand Up @@ -234,12 +225,8 @@ func main() {
return err
}

logFormat = cfg.App.Format
// If toml does not have format, use the flag format
if logFormat == ""{
logFormat = cfg.Format
}
if logFormat == "json" {

if cfg.LogFormat == "json" {
logrus.SetFormatter(&logrus.JSONFormatter{})
} else {
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
Expand Down Expand Up @@ -470,8 +457,11 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
if c.IsSet("root") {
cfg.Root = c.String("root")
}
if c.IsSet("format") {
cfg.Format = c.String("format")
if c.IsSet("log-format") {
// set format if not set by config toml
if cfg.LogFormat == "" {
cfg.LogFormat = c.String("log-format")
}
}
if c.IsSet("addr") || len(cfg.GRPC.Address) == 0 {
cfg.GRPC.Address = c.StringSlice("addr")
Expand Down
89 changes: 0 additions & 89 deletions docs/opt_flags.md

This file was deleted.

0 comments on commit 603472b

Please sign in to comment.