Skip to content

Commit

Permalink
refactor: use log/slog
Browse files Browse the repository at this point in the history
Use the log/slog package to keep the
consistency cross the repository. Use different
packages could evoke the situation described at:

golang/go#64015

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Jul 25, 2024
1 parent c1bd9d8 commit 1c2592f
Show file tree
Hide file tree
Showing 28 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package config

import (
"log/slog"
"os"
"strings"
"time"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/secrets"
clowder "github.com/redhatinsights/app-common-go/pkg/api/v1"
"github.com/spf13/viper"
"golang.org/x/exp/slog"
"k8s.io/utils/env"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/config/event.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package config

import (
"log/slog"

"github.com/podengo-project/idmsvc-backend/internal/api/event"
clowder "github.com/redhatinsights/app-common-go/pkg/api/v1"
"golang.org/x/exp/slog"
)

// TopicMap is used to map between real and internal topics, this is
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/impl/domain_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package impl

import (
"errors"
"log/slog"
"net/http"
"time"

Expand All @@ -13,7 +14,6 @@ import (
internal_errors "github.com/podengo-project/idmsvc-backend/internal/errors"
"github.com/podengo-project/idmsvc-backend/internal/interface/repository"
identity "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"golang.org/x/exp/slog"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/handler/impl/domain_handler_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package impl

import (
"fmt"
"log/slog"
"net/http"

"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/openlyinc/pointy"
"github.com/podengo-project/idmsvc-backend/internal/domain/model"
internal_errors "github.com/podengo-project/idmsvc-backend/internal/errors"
slog "golang.org/x/exp/slog"
"gorm.io/gorm"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/infrastructure/datastore/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"database/sql"
"fmt"

"log/slog"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/podengo-project/idmsvc-backend/internal/config"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/logger"
"golang.org/x/exp/slog"
pg "gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/datastore/hostconf_jwk_db.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package datastore

import (
"log/slog"
"time"

"github.com/podengo-project/idmsvc-backend/internal/config"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/token/hostconf_jwk"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/token/hostconf_jwk/model"
interface_repository "github.com/podengo-project/idmsvc-backend/internal/interface/repository"
"github.com/podengo-project/idmsvc-backend/internal/usecase/repository"
"golang.org/x/exp/slog"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/datastore/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datastore

import (
"fmt"
"log/slog"
"os"
"sort"
"strconv"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/podengo-project/idmsvc-backend/internal/config"
"golang.org/x/exp/slog"
)

const dbMirationScriptPath = "./scripts/db/migrations"
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/event/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package event
import (
"context"
"fmt"
"log/slog"
"strings"
"time"

"github.com/confluentinc/confluent-kafka-go/kafka"
schema "github.com/podengo-project/idmsvc-backend/internal/api/event"
"github.com/podengo-project/idmsvc-backend/internal/config"
"golang.org/x/exp/slog"
)

// https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
Expand Down
3 changes: 2 additions & 1 deletion internal/infrastructure/event/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package event
import (
"context"

"log/slog"

"github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/podengo-project/idmsvc-backend/internal/config"
"golang.org/x/exp/slog"
)

// Adapted from: https://github.com/RedHatInsights/playbook-dispatcher/blob/master/internal/response-consumer/main.go#L21
Expand Down
3 changes: 2 additions & 1 deletion internal/infrastructure/event/producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/json"
"fmt"

"log/slog"

"github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/openlyinc/pointy"
"github.com/podengo-project/idmsvc-backend/internal/config"
"golang.org/x/exp/slog"
)

// See: https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/event/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package event

import (
"fmt"
"log/slog"
"strings"

"github.com/confluentinc/confluent-kafka-go/kafka"
"golang.org/x/exp/slog"
)

func getHeaderString(headers []kafka.Header) string {
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/event/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"bufio"
"bytes"
"fmt"
"log/slog"
"testing"

"github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/openlyinc/pointy"
"github.com/podengo-project/idmsvc-backend/internal/api/event"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/event/message"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/slog"
)

func TestLogEventMessageInfo(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/logger/gorm_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"runtime"
"time"

"golang.org/x/exp/slog"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/logger/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logger
import (
"context"
"fmt"
"log/slog"
"os"
"runtime/debug"
"strings"
Expand All @@ -13,7 +14,6 @@ import (
aws_session "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/podengo-project/idmsvc-backend/internal/config"
"golang.org/x/exp/slog"
)

// If you want to learn more about slog visit:
Expand Down
3 changes: 1 addition & 2 deletions internal/infrastructure/logger/meta_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package logger

import (
"context"

"golang.org/x/exp/slog"
"log/slog"
)

// type SlogMetaHandler slog.Handler
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/logger/meta_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package logger
import (
"bytes"
"context"
"log/slog"
"os"
"testing"

"github.com/stretchr/testify/assert"
"golang.org/x/exp/slog"
)

func TestNewSlogMetaHandler(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/infrastructure/logger/middleware.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package logger

import (
"log/slog"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/podengo-project/idmsvc-backend/internal/api/header"
"golang.org/x/exp/slog"
)

// This requires the following values to be set in
Expand Down
3 changes: 2 additions & 1 deletion internal/infrastructure/middleware/enforce_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"errors"
"fmt"

"log/slog"

"github.com/labstack/echo/v4"
echo_middleware "github.com/labstack/echo/v4/middleware"
"github.com/podengo-project/idmsvc-backend/internal/api/header"
identity "github.com/redhatinsights/platform-go-middlewares/v2/identity"
slog "golang.org/x/exp/slog"
)

// FIXME Refactor to use the signature: func(c echo.Context) Error
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/middleware/rbac.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package middleware

import (
"log/slog"
"net/http"

"github.com/labstack/echo/v4"
echo_middleware "github.com/labstack/echo/v4/middleware"
"github.com/podengo-project/idmsvc-backend/internal/api/header"
rbac_data "github.com/podengo-project/idmsvc-backend/internal/infrastructure/middleware/rbac-data"
rbac_client "github.com/podengo-project/idmsvc-backend/internal/interface/client/rbac"
slog "golang.org/x/exp/slog"
)

// RBACConfig hold the skipper, route prefix, the rbac permissions
Expand Down Expand Up @@ -76,7 +76,7 @@ func RBACWithConfig(rbacConfig *RBACConfig) echo.MiddlewareFunc {
if err != nil {
return err
}
slog.ErrorCtx(c.Request().Context(), "unauthorized", "permission", permission)
slog.ErrorContext(c.Request().Context(), "unauthorized", "permission", permission)
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/service/impl/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package impl
import (
"context"
"fmt"
"log/slog"
"net/http"
"sync"

Expand All @@ -12,7 +13,6 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/router"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/service"
"github.com/podengo-project/idmsvc-backend/internal/metrics"
"golang.org/x/exp/slog"
)

type apiService struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/service/impl/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package impl

import (
"context"
"log/slog"
"sync"

api_event "github.com/podengo-project/idmsvc-backend/internal/api/event"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/event"
event_handler "github.com/podengo-project/idmsvc-backend/internal/infrastructure/event/handler"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/service"
"golang.org/x/exp/slog"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/service/impl/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package impl
import (
"context"
"fmt"
"log/slog"
"net/http"
"sync"

Expand All @@ -11,7 +12,6 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/handler"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/router"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/service"
"golang.org/x/exp/slog"
)

type metricsService struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "embed"
"errors"
"fmt"
"log/slog"
"net/http"
"net/url"
"os"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/config"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/logger"
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/service"
"golang.org/x/exp/slog"
"gopkg.in/yaml.v3"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package impl

import (
"log/slog"
"net/http"
"net/url"
"strconv"

"github.com/labstack/echo/v4"
"golang.org/x/exp/slog"
)

type queryParams struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/usecase/client/rbac/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"strings"

"github.com/podengo-project/idmsvc-backend/internal/api/header"
"github.com/podengo-project/idmsvc-backend/internal/interface/client/rbac"
slog "golang.org/x/exp/slog"
)

type rbacWrapper struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/usecase/repository/host_repository.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package repository

import (
"log/slog"
"net/http"
"time"

Expand All @@ -11,7 +12,6 @@ import (
"github.com/podengo-project/idmsvc-backend/internal/infrastructure/token/hostconf_token"
"github.com/podengo-project/idmsvc-backend/internal/interface/interactor"
"github.com/podengo-project/idmsvc-backend/internal/interface/repository"
"golang.org/x/exp/slog"
"gorm.io/gorm"
)

Expand Down
Loading

0 comments on commit 1c2592f

Please sign in to comment.