Update logging behavior

This commit is contained in:
Tom Wiesing 2022-12-01 12:42:04 +01:00
parent 3b78b06fff
commit 6f1ba24761
No known key found for this signature in database
28 changed files with 176 additions and 137 deletions

View file

@ -3,7 +3,6 @@ package home
import (
"bytes"
"context"
"fmt"
"io"
"time"
@ -11,6 +10,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static"
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
"golang.org/x/sync/errgroup"
)
@ -18,7 +18,7 @@ import (
func (home *Home) updateInstances(ctx context.Context, progress io.Writer) {
go func() {
for t := range timex.TickContext(ctx, home.RefreshInterval) {
fmt.Fprintf(progress, "[%s]: reloading instance list\n", t.Format(time.Stamp))
logging.ProgressF(progress, ctx, "[%s]: reloading instance list\n", t.Format(time.Stamp))
err := (func() error {
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
@ -33,7 +33,7 @@ func (home *Home) updateInstances(ctx context.Context, progress io.Writer) {
return nil
})()
if err != nil {
fmt.Fprintf(progress, "error reloading instances: %s", err.Error())
logging.ProgressF(progress, ctx, "error reloading instances: %s", err.Error())
}
}
}()
@ -55,7 +55,7 @@ func (home *Home) instanceMap(ctx context.Context) (map[string]struct{}, error)
func (home *Home) updateRender(ctx context.Context, progress io.Writer) {
go func() {
for t := range timex.TickContext(ctx, home.RefreshInterval) {
fmt.Fprintf(progress, "[%s]: reloading home render list\n", t.Format(time.Stamp))
logging.ProgressF(progress, ctx, "[%s]: reloading home render list\n", t.Format(time.Stamp))
err := (func() error {
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
@ -70,7 +70,7 @@ func (home *Home) updateRender(ctx context.Context, progress io.Writer) {
return nil
})()
if err != nil {
fmt.Fprintf(progress, "error reloading instances: %s", err.Error())
logging.ProgressF(progress, ctx, "error reloading instances: %s", err.Error())
}
}
}()

View file

@ -3,19 +3,19 @@ package home
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/FAU-CDI/wisski-distillery/pkg/timex"
)
func (home *Home) updateRedirect(ctx context.Context, progress io.Writer) {
go func() {
for t := range timex.TickContext(ctx, home.RefreshInterval) {
fmt.Fprintf(progress, "[%s]: reloading overrides\n", t.Format(time.Stamp))
logging.ProgressF(progress, ctx, "[%s]: reloading overrides\n", t.Format(time.Stamp))
err := (func() error {
ctx, cancel := context.WithTimeout(ctx, home.RefreshInterval)
@ -30,7 +30,7 @@ func (home *Home) updateRedirect(ctx context.Context, progress io.Writer) {
return nil
})()
if err != nil {
fmt.Fprintf(progress, "error reloading overrides: %s", err.Error())
logging.ProgressF(progress, ctx, "error reloading overrides: %s", err.Error())
}
}

View file

@ -2,9 +2,10 @@ package control
import (
"context"
"fmt"
"io"
"net/http"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
)
// Server returns an http.Mux that implements the main server instance.
@ -18,7 +19,7 @@ func (control *Control) Server(ctx context.Context, progress io.Writer) (*http.S
// add all the servable routes!
for _, s := range control.Servables {
for _, route := range s.Routes() {
fmt.Fprintf(progress, "mounting %s\n", route)
logging.ProgressF(progress, ctx, "mounting %s\n", route)
handler, err := s.Handler(ctx, route, progress)
if err != nil {
return nil, err