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
+7 -7
View File
@@ -14,7 +14,7 @@ import (
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/go-kit/log"
"github.com/fleetdm/fleet/v4/server/platform/logging"
"github.com/go-kit/log/level"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
@@ -33,7 +33,7 @@ type Schedule struct {
ctx context.Context
name string
instanceID string
logger log.Logger
logger *logging.Logger
defaultPrevRunCreatedAt time.Time // default timestamp of previous run for the schedule if none exists, time.Now if not set
@@ -92,9 +92,9 @@ type CronStatsStore interface {
type Option func(*Schedule)
// WithLogger sets a logger for the Schedule.
func WithLogger(l log.Logger) Option {
func WithLogger(l *logging.Logger) Option {
return func(s *Schedule) {
s.logger = log.With(l, "schedule", s.name)
s.logger = l.With("schedule", s.name)
}
}
@@ -168,7 +168,7 @@ func New(
ctx: ctx,
name: name,
instanceID: instanceID,
logger: log.NewNopLogger(),
logger: logging.NewNopLogger(),
trigger: make(chan struct{}),
done: make(chan struct{}),
configReloadInterval: 1 * time.Hour, // by default we will check for updated config once per hour
@@ -180,9 +180,9 @@ func New(
fn(sch)
}
if sch.logger == nil {
sch.logger = log.NewNopLogger()
sch.logger = logging.NewNopLogger()
}
sch.logger = log.With(sch.logger, "instanceID", instanceID)
sch.logger = sch.logger.With("instanceID", instanceID)
sch.errors = make(fleet.CronScheduleErrors)
return sch
}