Skip to content

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

Merged
getvictor merged 13 commits into
mainfrom
victor/38889-slog-infra
Feb 11, 2026
Merged

Changes needed before gokit/log to slog transition.#39527
getvictor merged 13 commits into
mainfrom
victor/38889-slog-infra

Conversation

@getvictor

@getvictor getvictor commented Feb 7, 2026

Copy link
Copy Markdown
Member

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.

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

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

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.

# Conflicts:
#	cmd/fleet/main.go
#	cmd/fleet/vuln_process.go
#	server/platform/logging/logging.go
@codecov

codecov Bot commented Feb 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.24390% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.23%. Comparing base (7009ca8) to head (f54eebf).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cmd/fleet/cron.go 25.64% 29 Missing ⚠️
cmd/fleet/serve.go 0.00% 8 Missing ⚠️
server/platform/logging/kitlog_adapter.go 76.92% 2 Missing and 1 partial ⚠️
server/service/handler.go 75.00% 3 Missing ⚠️
cmd/fleet/main.go 0.00% 2 Missing ⚠️
server/mdm/apple/apple_mdm.go 83.33% 2 Missing ⚠️
server/platform/logging/logging.go 80.00% 2 Missing ⚠️
server/service/apple_mdm.go 71.42% 2 Missing ⚠️
cmd/fleet/vuln_process.go 66.66% 1 Missing ⚠️
ee/server/calendar/google_calendar_load.go 0.00% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #39527      +/-   ##
==========================================
+ Coverage   66.22%   66.23%   +0.01%     
==========================================
  Files        2436     2436              
  Lines      195013   195017       +4     
  Branches     8454     8587     +133     
==========================================
+ Hits       129144   129173      +29     
+ Misses      54159    54138      -21     
+ Partials    11710    11706       -4     
Flag Coverage Δ
backend 68.01% <65.24%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Replaces go-kit/kitlog logging with the new slog-based server/platform/logging throughout the codebase: swaps logger types to *logging.Logger, updates imports, converts kitlog.With(...) to logger.With(...), and adjusts constructors/tests to use the new logging helpers.

Changes

Cohort / File(s) Summary
Core logging package
server/platform/logging/kitlog_adapter.go, server/platform/logging/kitlog_adapter_test.go, server/platform/logging/logging.go
Introduces new Logger adapter, renames constructors (e.g., NewLogger), adds NewNopLogger, NewLogfmtLogger, NewJSONLogger, and a DiscardHandler.
CLI & server init
cmd/fleet/main.go, cmd/fleet/serve.go, cmd/fleet/serve_test.go
Change initLogger return type to *logging.Logger, remove kitlog imports, and switch logger construction/With usage to the new logging package.
Cron & vuln processing
cmd/fleet/cron.go, cmd/fleet/cron_test.go, cmd/fleet/vuln_process.go
Replace kitlog.Logger with *logging.Logger across cron schedules and vulnerability flows; update ~80+ function signatures and propagate logger to nested components.
Maintained-apps
cmd/maintained-apps/*
Migrate AppCommander and validate tooling logger fields and constructors to *logging.Logger; update tests and platform logging initialization.
Calendar & cron modules
ee/server/calendar/..., server/cron/calendar_cron.go, server/cron/calendar_cron_test.go
Switch GoogleCalendar and calendar cron functions to *logging.Logger; replace kitlog.With with logger.With and pass logger through processing functions.
Conditional access / SCEP / SCIM
ee/server/service/condaccess/*, ee/server/scim/scim.go
Change public RegisterSCEP/RegisterIdP/RegisterSCIM signatures and internal services to accept *logging.Logger; update adapter and test usages.
Certificate / DigiCert
ee/server/service/digicert/digicert.go, server/service/request_certificate_test.go, server/service/certificate_authorities_test.go
Change public logger fields and WithLogger opt to *logging.Logger; update default logger construction.
MDM (DEP / Apple)
server/mdm/apple/*, server/service/apple_mdm.go, server/service/*_mdm_test.go
Migrate DEPService, NewDEPClient, MDM services and many helper functions to accept *logging.Logger; update logger.With usage and tests.
Service layer & handlers
server/service/service.go, server/service/handler.go, server/service/handler_test.go, server/service/testing_utils.go
Change Service/TestServerOpts/NanoMDMLogger types and multiple public handler constructors to accept *logging.Logger; update middleware and NanoMDM logger adapter implementations.
Worker infra
server/worker/worker.go, server/worker/*_test.go
Worker.log field and NewWorker signature updated to *logging.Logger; tests adjusted to use new logging helpers.
Integration tests & suites
server/service/integration_*.go, server/service/integrationtest/*, ee/server/integrationtest/*
Replace go-kit/log usage with server/platform/logging in many integration tests and BaseSuite; some tests adopt new record-based logging assertions.
NanoDEP & tooling
server/logging/nanodep.go, tools/mdm/apple/apnspush/main.go, cmd/fleetctl/*
NanoDEP logger constructor and methods changed to use *logging.Logger; tooling and fleetctl tests updated to use new log constructors.
Misc tests and utilities
many *_test.go files across repo (examples: server/fleet/mdm_test.go, server/service/osquery_test.go, server/worker/*_test.go)
Wide replacement of kitlog.NewNopLogger/NewJSONLogger/NewLogfmtLogger with logging equivalents; imports updated across tests.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ksykulev
  • georgekarrv
  • lucasmrod
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective: preparing for slog migration by updating logger types and removing kitlog.With usage patterns.
Linked Issues check ✅ Passed The PR fulfills issue #38889's Phase 1 foundation requirements: adopting *logging.Logger adapter, replacing kitlog.With patterns, and creating convenience functions for logging initialization.
Out of Scope Changes check ✅ Passed All changes are scoped to the foundational migration preparation. No unrelated refactoring, features, or out-of-scope modifications detected beyond the stated objectives.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering the purpose, key changes, and files requiring focus.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/38889-slog-infra

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/platform/logging/kitlog_adapter.go (1)

28-63: ⚠️ Potential issue | 🟡 Minor

Odd-length keyvals silently drops the last element.

If keyvals has an odd number of elements, the loop bound len(keyvals)-1 skips the trailing key. This mirrors go-kit/log's own behavior (it would pair the trailing key with ErrMissingValue), but the silent drop here is a slight behavior change. Unlikely to matter in practice since callers always pass pairs.

🧹 Nitpick comments (7)
ee/server/service/hostidentity/scep.go (1)

144-144: renewalMiddleware still accepts kitlog.Logger — consider migrating for consistency.

This unexported function still takes kitlog.Logger, which keeps the kitlog import alive. It works fine today since *logging.Logger satisfies the interface, but migrating it to *logging.Logger would let you drop the kitlog import from this file entirely and be consistent with the rest of the changes.

ee/server/service/condaccess/log_adapter.go (1)

10-12: Stale comment: references kitlog.Logger but the field is now *logging.Logger.

Line 10's comment still says "adapts kitlog.Logger to saml logger.Interface" but the logger field is now *logging.Logger. Consider updating the comment to reflect the new type.

Proposed fix
-// kitlogAdapter adapts kitlog.Logger to saml logger.Interface
+// kitlogAdapter adapts *logging.Logger to saml logger.Interface
server/service/integration_logger_test.go (1)

236-250: assertIPAddrLogged helper could produce confusing failures if multiple records have the attribute.

The helper counts occurrences of ip_addr and x_for_ip_addr across all records and asserts exactly 1 of each. If a future test case produces additional log records containing these attributes, the assertion will fail with a non-obvious message (expected 1, got 2). Consider adding a descriptive message to the assertions for easier debugging.

Suggested improvement
-		assert.Equal(t, 1, ipAddrCount)
-		assert.Equal(t, 1, xForIPAddrCount)
+		assert.Equal(t, 1, ipAddrCount, "expected exactly 1 record with ip_addr attribute")
+		assert.Equal(t, 1, xForIPAddrCount, "expected exactly 1 record with x_for_ip_addr attribute")
server/mdm/apple/apple_mdm.go (1)

19-31: Two similarly-named logging imports may cause confusion.

The file imports both "github.com/fleetdm/fleet/v4/server/logging" (as logging) and "github.com/fleetdm/fleet/v4/server/platform/logging" (as platformlogging). This is functional but the naming proximity could trip up future contributors.

Not blocking — just a note for awareness during the eventual Phase 3 cleanup when server/logging is retired.

cmd/fleet/serve.go (1)

85-86: Duplicate import of github.com/go-kit/log.

Both log (Line 85) and kitlog (Line 86) alias the same package. While both aliases appear to be in use (log.Logger on Line 2001, kitlog.Logger on Lines 1760/1921), consider unifying to a single alias to reduce confusion during the ongoing migration.

cmd/fleet/cron.go (2)

1173-1225: verifyDiskEncryptionKeys uses bare logger.Log(...) consistently.

Note that this function uses logger.Log("err", ...) and logger.Log("inf", ...) directly rather than going through level.Error(logger) or level.Info(logger). This is pre-existing behavior and not introduced by this PR, but it means these log lines won't have a level key. Consider aligning with level.Error(logger).Log(...) in a follow-up for consistency.


1486-1490: cleanupCronStatsOnShutdown also uses bare logger.Log.

Same observation as verifyDiskEncryptionKeys — no level key in log output. Pre-existing, not introduced here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prepares the codebase for a gradual go-kit/logslog migration by standardizing on Fleet’s server/platform/logging adapter and removing most remaining kitlog.With usage so log enrichment and future slog-native calls become simpler and type-safe.

Changes:

  • Replace many kitlog.Logger usages with *platform/logging.Logger and convert kitlog.With(...) to logger.With(...).
  • Update the core adapter (server/platform/logging) and add convenience constructors (NewNopLogger, NewLogfmtLogger, NewJSONLogger).
  • Refactor numerous unit/integration tests to validate logs via slog records/test handler rather than parsing serialized output.

Reviewed changes

Copilot reviewed 84 out of 84 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/mdm/apple/apnspush/main.go Switch tool logger to platform logging and With helper.
server/worker/worker_test.go Use platform NewNopLogger in worker tests.
server/worker/worker.go Worker now stores *logging.Logger; replace kitlog.With with logger.With.
server/worker/macos_setup_assistant_test.go Use platform NewNopLogger in test.
server/worker/db_migrations_test.go Use platform nop/JSON loggers in test scaffolding.
server/worker/apple_mdm_test.go Replace kitlog constructors with platform logging constructors.
server/service/testing_utils.go Update test server/logger plumbing to platform logging types.
server/service/testing_client.go Use platform nop logger for integration tests when disabled.
server/service/service_campaigns.go Replace log.With usage with svc.logger.With.
server/service/service.go Service stores *logging.Logger; constructor updated accordingly.
server/service/schedule/schedule.go Schedule now stores *logging.Logger; update logger option and defaults.
server/service/osquery_test.go Update test loggers to platform logging constructors.
server/service/osquery.go Replace log.With usage with svc.logger.With.
server/service/integrationtest/suite.go Integration suite logger type updated to *logging.Logger.
server/service/integrationtest/android/suite.go Use platform logfmt logger in suite setup.
server/service/integration_sso_test.go Use platform nop logger when integration-test logging disabled.
server/service/integration_smtp_test.go Use platform nop logger when integration-test logging disabled.
server/service/integration_mdm_test.go Replace kitlog constructors/types with platform logging equivalents.
server/service/integration_mdm_lifecycle_test.go Replace kitlog JSON logger with platform JSON logger.
server/service/integration_logger_test.go Rewrite log assertions to use slog.Record capture via test handler.
server/service/integration_live_queries_test.go Use platform nop logger when integration-test logging disabled.
server/service/integration_install_test.go Switch install test logger plumbing to platform logging.
server/service/integration_enterprise_test.go Switch enterprise integration tests to platform logging and With.
server/service/hosts_test.go Use platform nop logger in service struct construction.
server/service/handler_test.go Update handler tests to pass platform nop logger.
server/service/handler.go Handler APIs now accept *logging.Logger; replace kitlog.With with logger.With.
server/service/calendar/calendar.go Calendar helpers now accept *logging.Logger and use .With.
server/service/apple_mdm_test.go Replace kitlog usage with platform logging in MDM tests.
server/service/apple_mdm_ddm_test.go Use platform logfmt logger in DDM test.
server/service/apple_mdm.go Update MDM service structs/functions to use *platformlogging.Logger and .With.
server/pubsub/testing_utils.go Use platform nop logger for redis query results tests.
server/pubsub/redis_query_results.go Replace log.Logger with *logging.Logger; update With usage.
server/platform/logging/logging.go Add discard handler + convenience constructors for nop/logfmt/json loggers.
server/platform/logging/kitlog_adapter_test.go Update adapter test to assert on *Logger rather than old adapter type.
server/platform/logging/kitlog_adapter.go Rename/reshape adapter as Logger, add .With and .SlogLogger().
server/mdm/apple/apple_mdm_test.go Replace go-kit nop logger with platform nop logger.
server/mdm/apple/apple_mdm_external_test.go Replace go-kit nop logger with platform nop logger.
server/mdm/apple/apple_mdm.go Update DEP service to use *platformlogging.Logger and .With.
server/mdm/apple/apple_bm.go Update ABM metadata helpers to accept *logging.Logger.
server/logging/nanodep.go Update NanoDEP logger adapter to use *platform/logging.Logger.
server/launcher/server.go Launcher server now accepts *logging.Logger.
server/launcher/launcher_test.go Use platform nop logger in launcher test wrapper.
server/launcher/launcher.go Launcher wrapper now stores *logging.Logger.
server/health/health_test.go Use platform nop logger in health tests.
server/health/health.go Health handlers now take *logging.Logger and use .With.
server/fleet/mdm_test.go Use platform nop logger in DEP client test.
server/cron/calendar_cron_test.go Use platform logging constructors/types in calendar cron tests.
server/cron/calendar_cron.go Calendar cron functions now accept *logging.Logger and use .With.
ee/server/service/software_installers.go Replace log.With with svc.logger.With in EE service.
ee/server/service/service.go EE service now stores/accepts *logging.Logger.
ee/server/service/request_certificate_test.go Use platform logfmt logger in EE test.
ee/server/service/mdm_external_test.go Use platform nop logger in EE MDM external test.
ee/server/service/hostidentity/scep.go Host identity SCEP registration now takes *logging.Logger and .With.
ee/server/service/digicert/digicert.go DigiCert service now stores *logging.Logger; default logger updated.
ee/server/service/condaccess/scep.go Conditional access SCEP registration now takes *logging.Logger and .With.
ee/server/service/condaccess/log_adapter.go SAML log adapter updated to use *logging.Logger.
ee/server/service/condaccess/idp_test.go Use platform nop logger in conditional access IdP tests.
ee/server/service/condaccess/idp.go Conditional access IdP now stores/accepts *logging.Logger and .With.
ee/server/service/certificate_authorities_test.go Use platform logfmt logger in EE CA tests.
ee/server/service/calendar_test.go Use platform nop logger in EE calendar test.
ee/server/scim/scim.go SCIM registration now takes *logging.Logger and uses .With.
ee/server/integrationtest/scim/suite.go Use platform logfmt logger in SCIM integration suite.
ee/server/integrationtest/hostidentity/suite.go Use platform logfmt logger + .With for depot setup.
ee/server/integrationtest/condaccess/suite.go Use platform logfmt logger + .With for depot setup.
ee/server/calendar/google_calendar_test.go Use platform logfmt logger in calendar tests.
ee/server/calendar/google_calendar_mock.go Use platform logging and .With in mock API.
ee/server/calendar/google_calendar_load.go Use platform logging and .With in load API.
ee/server/calendar/google_calendar_integration_test.go Use platform logfmt logger in integration test config.
ee/server/calendar/google_calendar.go GoogleCalendarConfig now uses *logging.Logger.
cmd/maintained-apps/validate/windows.go Update callbacks to accept *logging.Logger.
cmd/maintained-apps/validate/main.go Replace kitlog setup/filtering with platform slog logger construction.
cmd/maintained-apps/validate/darwin.go Update callbacks to accept *logging.Logger.
cmd/maintained-apps/validate/app_commander_test.go Use platform nop logger in commander tests.
cmd/maintained-apps/validate/app_commander.go Commander now stores *logging.Logger.
cmd/maintained-apps/main.go Replace kitlog logger setup with platform slog logger construction.
cmd/fleetctl/fleetctl/trigger_test.go Use platform nop logger in fleetctl trigger tests.
cmd/fleetctl/fleetctl/query_test.go Use platform JSON logger without go-kit level filter setup.
cmd/fleet/vuln_process.go Use .With("cron", ...) on platform logger.
cmd/fleet/serve_test.go Update test schedule/logger wiring to platform logging types.
cmd/fleet/serve.go Replace kitlog.With calls with .With(...) on platform logger.
cmd/fleet/main.go initLogger now returns *logging.Logger and uses logging.NewLogger.
cmd/fleet/cron_test.go Use platform nop logger in cron tests.
cmd/fleet/cron.go Cron/scheduler functions now accept *logging.Logger and use .With.
.golangci.yml Exclude (*platform/logging.Logger).Log from errcheck exclusions list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/service/integration_logger_test.go Outdated
Comment thread server/service/integration_logger_test.go
@fleetdm fleetdm deleted a comment from Copilot AI Feb 8, 2026
@fleetdm fleetdm deleted a comment from Copilot AI Feb 8, 2026
@fleetdm fleetdm deleted a comment from Copilot AI Feb 8, 2026
@fleetdm fleetdm deleted a comment from Copilot AI Feb 8, 2026
@fleetdm fleetdm deleted a comment from Copilot AI Feb 8, 2026
@fleetdm fleetdm deleted a comment from Copilot AI Feb 8, 2026
@getvictor
getvictor marked this pull request as ready for review February 8, 2026 23:43
@getvictor
getvictor requested a review from a team as a code owner February 8, 2026 23:43
// This is a drop-in replacement for kitlog.NewJSONLogger().
func NewJSONLogger(output io.Writer) *Logger {
return NewLogger(NewSlogLogger(Options{Output: output, JSON: true, Debug: true}))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to hard code these to Debug: true always?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this is only used in tests. So, I don't think it is a big deal.

I think a better pattern is to tie logging to t.Log in tests so that we can see which test produced which log output. This is useful when tests run in parallel.

# Conflicts:
#	cmd/fleet/cron.go
#	cmd/fleet/serve_test.go
#	server/worker/worker_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slog migration (1)

3 participants