Skip to content

Commit

Permalink
feat: add program to log
Browse files Browse the repository at this point in the history
To help determine where the log is coming from, add a program field to
logs
  • Loading branch information
mloberg committed May 16, 2024
1 parent 758ff06 commit 4c0b399
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strconv"
)

Expand All @@ -14,6 +15,7 @@ type Config struct {
Region string
ServiceDefinition string
SkipValidation bool
Program string
}

// NewFromEnv creates a new Config from environment variables and defaults
Expand All @@ -25,6 +27,7 @@ func NewFromEnv() *Config {
Region: os.Getenv("AWS_REGION"),
ServiceDefinition: os.Getenv("SERVICE_DEFINITION"),
SkipValidation: false,
Program: "docker-bootstrap",
}

if s, err := strconv.ParseBool(os.Getenv("BOOTSTRAP_SKIP_VALIDATION")); err == nil {
Expand All @@ -48,6 +51,10 @@ func NewFromEnv() *Config {
cfg.ServiceDefinition = "service.json"
}

if ex, err := os.Executable(); err == nil {
cfg.Program = filepath.Base(ex)
}

return cfg
}

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {
slog.String("service", cfg.Service),
slog.String("product", cfg.Product),
slog.String("region", cfg.Region),
slog.String("program", cfg.Program),
)
slog.SetDefault(logger)

Expand Down

0 comments on commit 4c0b399

Please sign in to comment.