Skip to content

Commit

Permalink
Logging refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mantzas committed Oct 25, 2024
1 parent 8d126f9 commit c24c071
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions component/http/observability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func createProfilingTestCases(enableExpVar bool) map[string]profilingTestCase {
}

func TestLoggingRoutes(t *testing.T) {
log.Setup(&log.Config{
require.NoError(t, log.Setup(&log.Config{
IsJSON: true,
Level: "info",
})
}))
server := createServer(true)
defer server.Close()

t.Run("change log level to debug", func(t *testing.T) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, fmt.Sprintf("%s/debug/log/debug", server.URL), nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, server.URL+"/debug/log/debug", nil)
require.NoError(t, err)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
Expand All @@ -103,7 +103,7 @@ func TestLoggingRoutes(t *testing.T) {
})

t.Run("wrong log level", func(t *testing.T) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, fmt.Sprintf("%s/debug/log/xxx", server.URL), nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, server.URL+"/debug/log/xxx", nil)
require.NoError(t, err)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
Expand All @@ -112,7 +112,7 @@ func TestLoggingRoutes(t *testing.T) {
})

t.Run("empty log level", func(t *testing.T) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, fmt.Sprintf("%s/debug/log/", server.URL), nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, server.URL+"/debug/log/", nil)
require.NoError(t, err)
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
Expand Down
11 changes: 6 additions & 5 deletions observability/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSetup(t *testing.T) {
Expand All @@ -16,7 +17,7 @@ func TestSetup(t *testing.T) {
IsJSON: true,
Level: "debug",
}
assert.NoError(t, Setup(cfg))
require.NoError(t, Setup(cfg))
assert.NotNil(t, slog.Default())
})

Expand All @@ -26,7 +27,7 @@ func TestSetup(t *testing.T) {
IsJSON: false,
Level: "debug",
}
assert.NoError(t, Setup(cfg))
require.NoError(t, Setup(cfg))
assert.NotNil(t, slog.Default())
})
}
Expand All @@ -46,16 +47,16 @@ func TestContext(t *testing.T) {
}

func TestSetLevelAndCheckEnable(t *testing.T) {
Setup(&Config{
require.NoError(t, Setup(&Config{
Attributes: []slog.Attr{},
IsJSON: true,
Level: "info",
})
}))

assert.True(t, Enabled(slog.LevelInfo))
assert.False(t, Enabled(slog.LevelDebug))

assert.NoError(t, SetLevel("debug"))
require.NoError(t, SetLevel("debug"))

assert.True(t, Enabled(slog.LevelDebug))
}
Expand Down

0 comments on commit c24c071

Please sign in to comment.