Changes needed before gokit/log to slog transition. (#39527)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #38889

PLEASE READ BELOW before looking at file changes

Before converting individual files/packages to slog, we generally need
to make these 2 changes to make the conversion easier:
- Replace uses of `kitlog.With` since they are not fully compatible with
our kitlog adapter
- Directly use the kitlog adapter logger type instead of the kitlog
interface, which will let us have direct access to the underlying slog
logger: `*logging.Logger`

Note: that I did not replace absolutely all uses of `kitlog.Logger`, but
I did remove all uses of `kitlog.With` except for these due to
complexity:
- server/logging/filesystem.go and the other log writers (webhook,
firehose, kinesis, lambda, pubsub, nats)
- server/datastore/mysql/nanomdm_storage.go (adapter pattern)
- server/vulnerabilities/nvd/* (cascades to CLI tools)
- server/service/osquery_utils/queries.go (callback type signatures
cascade broadly)
- cmd/maintained-apps/ (standalone, so can be transitioned later all at
once)

Most of the changes in this PR follow these patterns:
- `kitlog.Logger` type → `*logging.Logger`
- `kitlog.With(logger, ...)` → `logger.With(...)`
- `kitlog.NewNopLogger() → logging.NewNopLogger()`, including similar
variations such as `logging.NewLogfmtLogger(w)` and
`logging.NewJSONLogger(w)`
- removed many now-unused kitlog imports

Unique changes that the PR review should focus on:
- server/platform/logging/kitlog_adapter.go: Core adapter changes
- server/platform/logging/logging.go: New convenience functions
- server/service/integration_logger_test.go: Test changes for slog

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
  - Was added in previous PR

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Migrated the codebase to a unified internal structured logging system
for more consistent, reliable logs and observability.
* No user-facing functionality changed; runtime behavior and APIs remain
compatible.
* **Tests**
* Updated tests to use the new logging helpers to ensure consistent test
logging and validation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Victor Lyuboslavsky
2026-02-11 10:08:33 -06:00
committed by GitHub
parent 37e7e84f3c
commit aaac4b1dfe
78 changed files with 603 additions and 572 deletions
+5 -4
View File
@@ -20,6 +20,7 @@ import (
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
"github.com/fleetdm/fleet/v4/server/dev_mode"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/platform/logging"
"github.com/fleetdm/fleet/v4/server/service/middleware/log"
"github.com/fleetdm/fleet/v4/server/service/middleware/otel"
kitlog "github.com/go-kit/log"
@@ -61,7 +62,7 @@ func (e *notFoundError) IsNotFound() bool {
// idpService implements the Okta conditional access IdP functionality.
type idpService struct {
ds fleet.Datastore
logger kitlog.Logger
logger *logging.Logger
certSerialFormat string
}
@@ -69,7 +70,7 @@ type idpService struct {
func RegisterIdP(
mux *http.ServeMux,
ds fleet.Datastore,
logger kitlog.Logger,
logger *logging.Logger,
fleetConfig *config.FleetConfig,
) error {
if fleetConfig == nil {
@@ -78,7 +79,7 @@ func RegisterIdP(
svc := &idpService{
ds: ds,
logger: kitlog.With(logger, "component", "conditional-access-idp"),
logger: logger.With("component", "conditional-access-idp"),
certSerialFormat: fleetConfig.ConditionalAccess.CertSerialFormat,
}
@@ -565,7 +566,7 @@ func (s *idpService) buildIdentityProvider(ctx context.Context, serverURL string
ssoURL = ssoURL.JoinPath(idpSSOPath)
// Create kitlog adapter for SAML library
samlLogger := &kitlogAdapter{logger: kitlog.With(s.logger, "component", "saml-idp")}
samlLogger := &kitlogAdapter{logger: s.logger.With("component", "saml-idp")}
// Build IdentityProvider
// Note: SessionProvider is set dynamically in serveSSO based on the authenticated device
+5 -5
View File
@@ -15,8 +15,8 @@ import (
"github.com/fleetdm/fleet/v4/server/config"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/mock"
"github.com/fleetdm/fleet/v4/server/platform/logging"
common_mysql "github.com/fleetdm/fleet/v4/server/platform/mysql"
kitlog "github.com/go-kit/log"
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/require"
)
@@ -76,13 +76,13 @@ b1ctZeF7HaWwFdTC8GqWI6zzRFn+YA3f/yYibhowuEypPQeSjlI=
func newTestService() (*idpService, *mock.Store) {
ds := new(mock.Store)
logger := kitlog.NewNopLogger()
logger := logging.NewNopLogger()
return &idpService{ds: ds, logger: logger, certSerialFormat: config.CertSerialFormatHex}, ds
}
func newTestServiceWithCertFormat(certFormat string) (*idpService, *mock.Store) {
ds := new(mock.Store)
logger := kitlog.NewNopLogger()
logger := logging.NewNopLogger()
return &idpService{ds: ds, logger: logger, certSerialFormat: certFormat}, ds
}
@@ -117,7 +117,7 @@ func mockCertAssetsFunc(includeCerts bool) func(context.Context, []fleet.MDMAsse
func TestRegisterIdP(t *testing.T) {
ds := new(mock.Store)
logger := kitlog.NewNopLogger()
logger := logging.NewNopLogger()
cfg := &config.FleetConfig{}
ds.AppConfigFunc = mockAppConfigFunc("https://fleet.example.com")
@@ -526,7 +526,7 @@ func TestParseCertAndKeyBytes(t *testing.T) {
}
func TestDeviceHealthSessionProvider(t *testing.T) {
logger := kitlog.NewNopLogger()
logger := logging.NewNopLogger()
now := time.Now()
tests := []struct {
+3 -3
View File
@@ -3,13 +3,13 @@ package condaccess
import (
"fmt"
kitlog "github.com/go-kit/log"
"github.com/fleetdm/fleet/v4/server/platform/logging"
"github.com/go-kit/log/level"
)
// kitlogAdapter adapts kitlog.Logger to saml logger.Interface
// kitlogAdapter adapts to saml logger.Interface
type kitlogAdapter struct {
logger kitlog.Logger
logger *logging.Logger
}
func (k *kitlogAdapter) Printf(format string, v ...interface{}) {
+4 -4
View File
@@ -15,9 +15,9 @@ import (
"github.com/fleetdm/fleet/v4/server/mdm/assets"
scepdepot "github.com/fleetdm/fleet/v4/server/mdm/scep/depot"
scepserver "github.com/fleetdm/fleet/v4/server/mdm/scep/server"
"github.com/fleetdm/fleet/v4/server/platform/logging"
"github.com/fleetdm/fleet/v4/server/service/middleware/otel"
"github.com/go-kit/kit/log"
kitlog "github.com/go-kit/log"
"github.com/smallstep/scep"
)
@@ -45,7 +45,7 @@ func RegisterSCEP(
mux *http.ServeMux,
scepStorage scepdepot.Depot,
ds fleet.Datastore,
logger kitlog.Logger,
logger *logging.Logger,
fleetConfig *config.FleetConfig,
) error {
if fleetConfig == nil {
@@ -68,10 +68,10 @@ func RegisterSCEP(
scepService := NewSCEPService(
ds,
signer,
kitlog.With(logger, "component", "conditional-access-scep"),
logger.With("component", "conditional-access-scep"),
)
scepLogger := kitlog.With(logger, "component", "http-conditional-access-scep")
scepLogger := logger.With("component", "http-conditional-access-scep")
e := scepserver.MakeServerEndpoints(scepService)
e.GetEndpoint = scepserver.EndpointLoggingMiddleware(scepLogger)(e.GetEndpoint)
e.PostEndpoint = scepserver.EndpointLoggingMiddleware(scepLogger)(e.PostEndpoint)