Skip to content

Commit

Permalink
Set server log level from config
Browse files Browse the repository at this point in the history
- Add controller compile command to README
- Remove debug println
  • Loading branch information
calvinmclean committed Apr 23, 2024
1 parent c416cc0 commit 5e23899
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ And that's it! I encourage you to check out the additional documentation for mor
## Frontend
This project includes an HTMX UI served by the Go application.
## Compile controller
```
pio run -t upload
```
1 change: 0 additions & 1 deletion garden-app/pkg/garden.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ func (g *Garden) Bind(r *http.Request) error {
g.LightSchedule = nil
}
if g.LightSchedule != nil {
fmt.Println(g.LightSchedule.Duration, g.LightSchedule.StartTime)
if g.LightSchedule.Duration == nil {
return errors.New("missing required light_schedule.duration field")
}
Expand Down
5 changes: 3 additions & 2 deletions garden-app/server/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ type LogConfig struct {

// GetHandler returns a slog handler based on the input. Valid values are "json", otherwise default text is used
func (c LogConfig) getHandler(writer io.Writer) slog.Handler {
opts := &slog.HandlerOptions{Level: c.GetLogLevel()}
switch c.Format {
case "json":
return slog.NewJSONHandler(writer, nil)
return slog.NewJSONHandler(writer, opts)
default:
return slog.NewTextHandler(writer, nil)
return slog.NewTextHandler(writer, opts)
}
}

Expand Down
1 change: 1 addition & 0 deletions garden-app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewServer(cfg Config, validateData bool) (*Server, error) {
html.SetFuncs(templateFuncs)

logger := cfg.LogConfig.NewLogger().With("source", "server")
slog.SetDefault(logger)

rootAPI := babyapi.NewRootAPI("root", "/")

Expand Down

0 comments on commit 5e23899

Please sign in to comment.