diff --git a/changes/40054-slog-2 b/changes/40054-slog-2 new file mode 100644 index 00000000000..a380136e4ae --- /dev/null +++ b/changes/40054-slog-2 @@ -0,0 +1 @@ +* Finished migrating code from go-kit/log to slog. diff --git a/server/service/apple_mdm.go b/server/service/apple_mdm.go index ffd81ec6ea8..9790c8ea89e 100644 --- a/server/service/apple_mdm.go +++ b/server/service/apple_mdm.go @@ -58,7 +58,6 @@ import ( "github.com/fleetdm/fleet/v4/server/platform/endpointer" "github.com/fleetdm/fleet/v4/server/ptr" "github.com/fleetdm/fleet/v4/server/variables" - "github.com/go-kit/log/level" "github.com/google/uuid" "github.com/micromdm/plist" "github.com/smallstep/pkcs7" @@ -278,7 +277,7 @@ func (svc *Service) ListMDMAppleCommands(ctx context.Context, opts *fleet.MDMCom } if authzErr != nil { - level.Error(svc.logger).Log("err", "unauthorized to view some team commands", "details", authzErr) + svc.logger.ErrorContext(ctx, "unauthorized to view some team commands", "details", authzErr) // filter-out the teams that the user is not allowed to view allowedResults := make([]*fleet.MDMAppleCommand, 0, len(results)) @@ -1991,7 +1990,7 @@ func (svc *Service) GetMDMAppleAccountEnrollmentProfile(ctx context.Context, enr func (svc *Service) ReconcileMDMAppleEnrollRef(ctx context.Context, enrollRef string, machineInfo *fleet.MDMAppleMachineInfo) (string, error) { if machineInfo == nil { // TODO: what to do here? We can't reconcile the enroll ref without machine info - level.Info(svc.logger).Log("msg", "missing machine info, failing enroll ref check", "enroll_ref", enrollRef) + svc.logger.InfoContext(ctx, "missing machine info, failing enroll ref check", "enroll_ref", enrollRef) return "", &fleet.BadRequestError{ Message: "missing deviceinfo", } @@ -2001,7 +2000,7 @@ func (svc *Service) ReconcileMDMAppleEnrollRef(ctx context.Context, enrollRef st if err != nil && !fleet.IsNotFound(err) { return "", ctxerr.Wrap(ctx, err, "check legacy enroll ref") } - level.Info(svc.logger).Log("msg", "check legacy enroll ref", "host_uuid", machineInfo.UDID, "legacy_enroll_ref", legacyRef) + svc.logger.InfoContext(ctx, "check legacy enroll ref", "host_uuid", machineInfo.UDID, "legacy_enroll_ref", legacyRef) return legacyRef, nil } @@ -2062,14 +2061,14 @@ func (svc *Service) CheckMDMAppleEnrollmentWithMinimumOSVersion(ctx context.Cont svc.authz.SkipAuthorization(ctx) if m == nil { - level.Debug(svc.logger).Log("msg", "no machine info, skipping os version check") + svc.logger.DebugContext(ctx, "no machine info, skipping os version check") return nil, nil } - level.Debug(svc.logger).Log("msg", "checking os version", "serial", m.Serial, "current_version", m.OSVersion) + svc.logger.DebugContext(ctx, "checking os version", "serial", m.Serial, "current_version", m.OSVersion) if !m.MDMCanRequestSoftwareUpdate { - level.Debug(svc.logger).Log("msg", "mdm cannot request software update, skipping os version check", "serial", m.Serial) + svc.logger.DebugContext(ctx, "mdm cannot request software update, skipping os version check", "serial", m.Serial) return nil, nil } @@ -2079,14 +2078,14 @@ func (svc *Service) CheckMDMAppleEnrollmentWithMinimumOSVersion(ctx context.Cont } if !needsUpdate { - level.Debug(svc.logger).Log("msg", "device is above minimum or update new host not checked, skipping os version check", "serial", m.Serial) + svc.logger.DebugContext(ctx, "device is above minimum or update new host not checked, skipping os version check", "serial", m.Serial) return nil, nil } sur, err := svc.getAppleSoftwareUpdateRequiredForDEPEnrollment(*m) if err != nil { // log for debugging but allow enrollment to proceed - level.Info(svc.logger).Log("msg", "getting apple software update required", "serial", m.Serial, "err", err) + svc.logger.InfoContext(ctx, "getting apple software update required", "serial", m.Serial, "err", err) return nil, nil } @@ -2107,8 +2106,7 @@ func (svc *Service) needsOSUpdateForDEPEnrollment(ctx context.Context, m fleet.M platform, settings, err := svc.ds.GetMDMAppleOSUpdatesSettingsByHostSerial(ctx, m.Serial) if err != nil { if fleet.IsNotFound(err) { - level.Info(svc.logger).Log( - "msg", "checking os updates settings, settings not found", + svc.logger.InfoContext(ctx, "checking os updates settings, settings not found", "serial", m.Serial, ) return false, nil @@ -2123,8 +2121,7 @@ func (svc *Service) needsOSUpdateForDEPEnrollment(ctx context.Context, m fleet.M if platform == "darwin" { updateNewHosts := settings.UpdateNewHosts.Set && settings.UpdateNewHosts.Valid && settings.UpdateNewHosts.Value - level.Info(svc.logger).Log( - "msg", "checking os updates settings for macos, update will be forced if UpdateNewHosts is set", + svc.logger.InfoContext(ctx, "checking os updates settings for macos, update will be forced if UpdateNewHosts is set", "update_new_hosts", updateNewHosts, "serial", m.Serial, ) @@ -2133,8 +2130,7 @@ func (svc *Service) needsOSUpdateForDEPEnrollment(ctx context.Context, m fleet.M // TODO: confirm what this check should do if !hasMinVersion { - level.Info(svc.logger).Log( - "msg", "checking os updates settings, minimum version not set", + svc.logger.InfoContext(ctx, "checking os updates settings, minimum version not set", "serial", m.Serial, "current_version", m.OSVersion, "minimum_version", minVersion, @@ -2143,8 +2139,7 @@ func (svc *Service) needsOSUpdateForDEPEnrollment(ctx context.Context, m fleet.M needsUpdate, err := apple_mdm.IsLessThanVersion(m.OSVersion, minVersion) if err != nil { - level.Info(svc.logger).Log( - "msg", "checking os updates settings, cannot compare versions", + svc.logger.InfoContext(ctx, "checking os updates settings, cannot compare versions", "serial", m.Serial, "current_version", m.OSVersion, "minimum_version", minVersion, @@ -2204,7 +2199,7 @@ func (svc *Service) mdmPushCertTopic(ctx context.Context) (string, error) { // It is a no-op for non-Apple hosts. func (svc *Service) enqueueMDMAppleCommandRemoveEnrollmentProfile(ctx context.Context, host *fleet.Host) error { if !fleet.IsApplePlatform(host.Platform) { - level.Debug(svc.logger).Log("msg", "Skipping mdm apple remove profile command for non-Apple host", "host_id", host.ID, "platform", host.Platform) + svc.logger.DebugContext(ctx, "Skipping mdm apple remove profile command for non-Apple host", "host_id", host.ID, "platform", host.Platform) return nil // no-op for non-Apple hosts } @@ -3405,7 +3400,7 @@ func (svc *MDMAppleCheckinAndCommandService) Authenticate(r *mdm.Request, m *mdm SCEPRenewalInProgress: scepRenewalInProgress, UserEnrollmentID: m.EnrollmentID, }); err != nil { - level.Warn(svc.logger).Log("msg", "could not reset Apple mdm information", "UDID", m.UDID, "EnrollmentID", m.EnrollmentID, "err", err) + svc.logger.WarnContext(r.Context, "could not reset Apple mdm information", "UDID", m.UDID, "EnrollmentID", m.EnrollmentID, "err", err) return err } @@ -3415,7 +3410,7 @@ func (svc *MDMAppleCheckinAndCommandService) Authenticate(r *mdm.Request, m *mdm err = svc.keyValueStore.Set(r.Context, fleet.StickyMDMEnrollmentKeyPrefix+r.ID, "1", fleet.StickyMDMEnrollmentTTL) if err != nil { // We do not want to fail here, just log the error to notify - level.Error(svc.logger).Log("msg", "failed to set sticky mdm enrollment key", "err", err, "host_uuid", r.ID) + svc.logger.ErrorContext(r.Context, "failed to set sticky mdm enrollment key", "err", err, "host_uuid", r.ID) } } } @@ -3429,7 +3424,7 @@ func (svc *MDMAppleCheckinAndCommandService) Authenticate(r *mdm.Request, m *mdm // // [1]: https://developer.apple.com/documentation/devicemanagement/token_update func (svc *MDMAppleCheckinAndCommandService) TokenUpdate(r *mdm.Request, m *mdm.TokenUpdate) error { - svc.logger.Log("info", "received token update", "host_uuid", r.ID) + svc.logger.InfoContext(r.Context, "received token update", "host_uuid", r.ID) info, err := svc.ds.GetHostMDMCheckinInfo(r.Context, r.ID) if err != nil { return ctxerr.Wrap(r.Context, err, "getting checkin info") @@ -3439,11 +3434,11 @@ func (svc *MDMAppleCheckinAndCommandService) TokenUpdate(r *mdm.Request, m *mdm. // much more difficult to reason about the state of the host. We should try instead // to centralize the flow control in the lifecycle methods. if info.SCEPRenewalInProgress { - svc.logger.Log("info", "token update received for a SCEP renewal in process, cleaning SCEP refs", "host_uuid", r.ID) + svc.logger.InfoContext(r.Context, "token update received for a SCEP renewal in process, cleaning SCEP refs", "host_uuid", r.ID) if err := svc.ds.CleanSCEPRenewRefs(r.Context, r.ID); err != nil { return ctxerr.Wrap(r.Context, err, "cleaning SCEP refs") } - svc.logger.Log("info", "cleaned SCEP refs, skipping setup experience and mdm lifecycle turn on action", "host_uuid", r.ID) + svc.logger.InfoContext(r.Context, "cleaned SCEP refs, skipping setup experience and mdm lifecycle turn on action", "host_uuid", r.ID) return nil } @@ -3453,7 +3448,7 @@ func (svc *MDMAppleCheckinAndCommandService) TokenUpdate(r *mdm.Request, m *mdm. if m.AwaitingConfiguration { // Note that Setup Experience is only skipped for macOS during DEP migration. iOS and iPadOS will still get VPP apps if info.MigrationInProgress && info.Platform == "darwin" { - svc.logger.Log("info", "skipping setup experience enqueueing because DEP migration is in progress", "host_uuid", r.ID) + svc.logger.InfoContext(r.Context, "skipping setup experience enqueueing because DEP migration is in progress", "host_uuid", r.ID) } else { enqueueSetupExperienceItems = true } @@ -3509,7 +3504,8 @@ func (svc *MDMAppleCheckinAndCommandService) TokenUpdate(r *mdm.Request, m *mdm. } if fleet.IsNotFound(err) || idpAccount == nil { // This should never happen but we still want to process the token update - level.Error(svc.logger).Log("msg", "no IDP account found for User (Device) enrollment even though a bearer token was passed", "host_uuid", r.ID, "account_uuid", accountUUID) + svc.logger.ErrorContext(r.Context, "no IDP account found for User (Device) enrollment even though a bearer token was passed", + "host_uuid", r.ID, "account_uuid", accountUUID) } else { acctUUID = idpAccount.UUID err = svc.ds.AssociateHostMDMIdPAccount(r.Context, r.ID, acctUUID) @@ -3586,7 +3582,7 @@ func (svc *MDMAppleCheckinAndCommandService) GetBootstrapToken(*mdm.Request, *md // // [1]: https://developer.apple.com/documentation/devicemanagement/userauthenticate func (svc *MDMAppleCheckinAndCommandService) UserAuthenticate(r *mdm.Request, ua *mdm.UserAuthenticate) ([]byte, error) { - level.Debug(svc.logger).Log("msg", "declining management of network user", "host_uuid", r.ID, "host_user_uuid", ua.UserID) + svc.logger.DebugContext(r.Context, "declining management of network user", "host_uuid", r.ID, "host_user_uuid", ua.UserID) return nil, nano_service.NewHTTPStatusError(http.StatusGone, ctxerr.New(r.Context, "userAuthenticate not supported")) } @@ -3788,7 +3784,7 @@ func (svc *MDMAppleCheckinAndCommandService) CommandAndReportResults(r *mdm.Requ if err := svc.ds.RetryVPPInstall(r.Context, vppInstall); err != nil { return nil, ctxerr.Wrap(r.Context, err, "retrying VPP install for host") } - level.Info(svc.logger).Log("msg", "re-queued VPP app installation", + svc.logger.InfoContext(r.Context, "re-queued VPP app installation", "host_id", vppInstall.HostID, "command_uuid", cmdResult.CommandUUID, "retry_count", vppInstall.RetryCount+1, "error_status", cmdResult.Status) return nil, nil @@ -3805,7 +3801,8 @@ func (svc *MDMAppleCheckinAndCommandService) CommandAndReportResults(r *mdm.Requ } else if updated { // TODO: call next step of setup experience? fromSetupExperience = true - level.Debug(svc.logger).Log("msg", "setup experience VPP install result updated", "host_uuid", cmdResult.Identifier(), "execution_id", cmdResult.CommandUUID) + svc.logger.DebugContext(r.Context, "setup experience VPP install result updated", + "host_uuid", cmdResult.Identifier(), "execution_id", cmdResult.CommandUUID) } user, act, err := svc.ds.GetPastActivityDataForVPPAppInstall(r.Context, cmdResult) if err != nil { @@ -3848,7 +3845,7 @@ func (svc *MDMAppleCheckinAndCommandService) CommandAndReportResults(r *mdm.Requ return nil, ctxerr.Wrap(r.Context, err, "failed to mark host as non longer awaiting configuration") } case "InstalledApplicationList": - level.Debug(svc.logger).Log("msg", "calling handlers for InstalledApplicationList") + svc.logger.DebugContext(r.Context, "calling handlers for InstalledApplicationList") host, err := svc.ds.HostByIdentifier(r.Context, cmdResult.Identifier()) if err != nil { return nil, ctxerr.Wrap(r.Context, err, "get host by identifier") @@ -3905,7 +3902,8 @@ func (svc *MDMAppleCheckinAndCommandService) handleRefetch(r *mdm.Request, cmdRe if r.Params != nil { if _, err := svc.maybeUpdateIDeviceEnrollRef(ctx, host, r.Params["enroll_reference"]); err != nil { // TODO: consider if we want to return an error here, for now we just log and continue - level.Error(svc.logger).Log("msg", "maybe update enroll reference", "host_uuid", host.UUID, "enroll_reference", r.Params["enroll_reference"], "err", err) + svc.logger.ErrorContext(ctx, "maybe update enroll reference", + "host_uuid", host.UUID, "enroll_reference", r.Params["enroll_reference"], "err", err) } } return svc.handleRefetchDeviceResults(ctx, host, cmdResult) @@ -3919,7 +3917,8 @@ func (svc *MDMAppleCheckinAndCommandService) handleRefetch(r *mdm.Request, cmdRe func (svc *MDMAppleCheckinAndCommandService) maybeUpdateIDeviceEnrollRef(ctx context.Context, host *fleet.Host, enrollRef string) (bool, error) { if host.Platform != "ios" && host.Platform != "ipados" { // caller should ensure this doesn't happen, but just in case we'll log it and return false - level.Debug(svc.logger).Log("msg", "unexpected usage of maybeUpdateIDeviceEnrollRef for non-iOS/non-iPadOS host", "host_id", host.ID, "host_uuid", host.UUID, "platform", host.Platform) + svc.logger.DebugContext(ctx, "unexpected usage of maybeUpdateIDeviceEnrollRef for non-iOS/non-iPadOS host", + "host_id", host.ID, "host_uuid", host.UUID, "platform", host.Platform) return false, nil } hmer, err := svc.ds.GetMDMAppleHostMDMEnrollRef(ctx, host.ID) @@ -3931,14 +3930,15 @@ func (svc *MDMAppleCheckinAndCommandService) maybeUpdateIDeviceEnrollRef(ctx con return false, nil } - level.Info(svc.logger).Log("msg", "updating enroll reference for host", "host_id", host.ID, "host_uuid", host.UUID, "old_enroll_ref", hmer, "new_enroll_ref", enrollRef) + svc.logger.InfoContext(ctx, "updating enroll reference for host", + "host_id", host.ID, "host_uuid", host.UUID, "old_enroll_ref", hmer, "new_enroll_ref", enrollRef) didUpdate, err := svc.ds.UpdateMDMAppleHostMDMEnrollRef(ctx, host.ID, enrollRef) if err != nil { return false, ctxerr.Wrap(ctx, err, "updating enroll reference") } if !didUpdate { - level.Debug(svc.logger).Log("msg", "unexpected enroll reference update no-op", "host_id", host.ID, "host_uuid", host.UUID) + svc.logger.DebugContext(ctx, "unexpected enroll reference update no-op", "host_id", host.ID, "host_uuid", host.UUID) } // clear SCEP renew refs if any @@ -4069,7 +4069,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( if host.TimeZone == nil || *host.TimeZone == "" { // We cannot determine if it's safe to schedule an update on this host. - level.Debug(logger).Log("msg", "skipping updates, host has no timezone") + logger.DebugContext(ctx, "skipping updates, host has no timezone") return nil } @@ -4080,7 +4080,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( case err == nil: // OK case fleet.IsNotFound(err): - level.Debug(logger).Log("msg", "no VPP token configured for this host's team") + logger.DebugContext(ctx, "no VPP token configured for this host's team") return nil default: return ctxerr.Wrap(ctx, err, "get VPP token if can install VPP apps") @@ -4092,11 +4092,11 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( return ctxerr.Wrap(ctx, err, "getting nano mdm enrollment") } if enrollment == nil { - level.Debug(logger).Log("msg", "skipping updates, missing nano enrollment type") + logger.DebugContext(ctx, "skipping updates, missing nano enrollment type") return nil } if enrollment.Type == mdm.EnrollType(mdm.UserEnrollmentDevice).String() { - level.Debug(logger).Log("msg", "skipping updates, software install isn't supported on personal (BYOD) iOS and iPadOS hosts") + logger.DebugContext(ctx, "skipping updates, software install isn't supported on personal (BYOD) iOS and iPadOS hosts") return nil } @@ -4127,8 +4127,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // Nothing else to do. return nil } - level.Debug(logger).Log( - "msg", "found software with auto update scheduled", + logger.DebugContext(ctx, "found software with auto update scheduled", "count", len(softwaresWithAutoUpdateSchedule), ) @@ -4154,16 +4153,13 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( *softwareWithAutoUpdateSchedule.AutoUpdateEndTime, ) if err != nil { - level.Error(logger).Log( - "msg", "skipping software, failed to check if timezone is in window", + logger.ErrorContext(ctx, "skipping software, failed to check if timezone is in window", "err", err, ) continue } if !ok { - level.Debug(logger).Log( - "msg", "host's local time is not within update window", - ) + logger.DebugContext(ctx, "host's local time is not within update window") continue } softwaresWithinUpdateSchedule = append(softwaresWithinUpdateSchedule, softwareWithAutoUpdateSchedule) @@ -4172,8 +4168,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // Nothing else to do. return nil } - level.Debug(logger).Log( - "msg", "found software with auto update scheduled, with host local time currently in window", + logger.DebugContext(ctx, "found software with auto update scheduled, with host local time currently in window", "count", len(softwaresWithinUpdateSchedule), ) @@ -4190,8 +4185,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( } softwareTitle, err := svc.ds.SoftwareTitleByID(ctx, softwareWithAutoUpdateSchedule.TitleID, teamID, fleet.TeamFilter{}) if err != nil { - level.Error(logger).Log( - "msg", "software title by id", + logger.ErrorContext(ctx, "software title by id", "software_title_id", softwareWithAutoUpdateSchedule.TitleID, "team_id", host.TeamID, "err", err, @@ -4210,15 +4204,13 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( case err == nil: // OK case fleet.IsNotFound(err): - level.Error(logger).Log( - "msg", "title should be VPP app", + logger.ErrorContext(ctx, "title should be VPP app", "software_title_id", softwareTitle.ID, "team_id", host.TeamID, ) continue default: - level.Error(logger).Log( - "msg", "get VPP app metadata by team and title", + logger.ErrorContext(ctx, "get VPP app metadata by team and title", "software_title_id", softwareTitle.ID, "team_id", host.TeamID, "err", err, @@ -4237,8 +4229,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // There are some cases where InstalledApplicationList skips the software from the list // when the update is ocurring. It seems the software is probably being skipped because // it's on a temporary state of installation/replacement. - level.Debug(logger).Log( - "msg", "software title not installed on device or currently in the process of updating, skipping from update", + logger.DebugContext(ctx, "software title not installed on device or currently in the process of updating, skipping from update", "name", softwareTitle.Name, "bundle_identifier", bundleIdentifier, "source", softwareTitle.Source, @@ -4260,30 +4251,25 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // // // Note that "Installing" is true and there's no "ShortVersion": - level.Error(logger).Log( - "msg", "skipping software, currently installing", - ) + logger.ErrorContext(ctx, "skipping software, currently installing") continue } if _, err := fleet.VersionToSemverVersion(installedVersion); err != nil { - level.Error(logger).Log( - "msg", "invalid installed version", + logger.ErrorContext(ctx, "invalid installed version", "version", installedVersion, ) continue } latestVersion := toValidSemVer(softwareTitle.AppStoreApp.LatestVersion) if _, err := fleet.VersionToSemverVersion(latestVersion); err != nil { - level.Error(logger).Log( - "msg", "invalid latest version", + logger.ErrorContext(ctx, "invalid latest version", "version", latestVersion, ) continue } if fleet.CompareVersions(latestVersion, installedVersion) != 1 { // Installed version is equal or higher than latest version, so nothing to do here. - level.Debug(logger).Log( - "msg", "skipping software version", + logger.DebugContext(ctx, "skipping software version", "latest_version", latestVersion, "installed_version", installedVersion, ) @@ -4296,8 +4282,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // Nothing else to do. return nil } - level.Debug(logger).Log( - "msg", "found software with auto update scheduled, with host local time currently in window, that need update", + logger.DebugContext(ctx, "found software with auto update scheduled, with host local time currently in window, that need update", "count", len(softwaresWithinUpdateWindowThatNeedUpdate), ) @@ -4317,15 +4302,13 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( softwareTitle, ok := softwareTitles[softwareWithinUpdateSchedule.TitleID] if !ok { // "Should not happen", so we log it just in case. - level.Error(logger).Log( - "msg", "missing title ID from map", + logger.ErrorContext(ctx, "missing title ID from map", "software_title_id", softwareWithinUpdateSchedule.TitleID, ) continue } if _, ok := adamIDsRecentInstallForHost[softwareTitle.AppStoreApp.AdamID]; ok { - level.Debug(logger).Log( - "msg", "skipping software, recent install for title", + logger.DebugContext(ctx, "skipping software, recent install for title", "software_title_id", softwareTitle.ID, "adam_id", softwareTitle.AppStoreApp.AdamID, ) @@ -4337,8 +4320,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // Nothing else to do. return nil } - level.Debug(logger).Log( - "msg", "found software with auto update scheduled, with host local time currently in window, that need update, no recent install", + logger.DebugContext(ctx, "found software with auto update scheduled, with host local time currently in window, that need update, no recent install", "count", len(softwaresWithinUpdateScheduleNoRecentInstalls), ) @@ -4352,15 +4334,13 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( softwareTitle, ok := softwareTitles[softwareWithinUpdateSchedule.TitleID] if !ok { // "Should not happen", so we log it just in case. - level.Error(logger).Log( - "msg", "missing title ID from map", + logger.ErrorContext(ctx, "missing title ID from map", "software_title_id", softwareWithinUpdateSchedule.TitleID, ) continue } if _, ok := adamIDsPendingInstallForHost[softwareTitle.AppStoreApp.AdamID]; ok { - level.Debug(logger).Log( - "msg", "skipping software, pending install for title", + logger.DebugContext(ctx, "skipping software, pending install for title", "software_title_id", softwareTitle.ID, "adam_id", softwareTitle.AppStoreApp.AdamID, ) @@ -4372,8 +4352,8 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // Nothing else to do. return nil } - level.Debug(logger).Log( - "msg", "found software with auto update scheduled, with host local time currently in window, that need update, no recent install, no pending installation", + logger.DebugContext(ctx, + "found software with auto update scheduled, with host local time currently in window, that need update, no recent install, no pending installation", "count", len(softwaresWithinUpdateScheduleToInstall), ) @@ -4393,8 +4373,7 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( vppApp, err := svc.ds.GetVPPAppByTeamAndTitleID(ctx, host.TeamID, softwareTitle.ID) if err != nil { - level.Error(logger).Log( - "msg", "get VPP app by team and title", + logger.ErrorContext(ctx, "get VPP app by team and title", "err", err, ) continue @@ -4403,16 +4382,13 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( // Check the label scoping for this VPP app and host. scoped, err := svc.ds.IsVPPAppLabelScoped(ctx, vppApp.VPPAppTeam.AppTeamID, host.ID) if err != nil { - level.Error(logger).Log( - "msg", "get VPP app by team and title", + logger.ErrorContext(ctx, "get VPP app by team and title", "err", err, ) continue } if !scoped { - level.Debug(logger).Log( - "msg", "skipping host because it's not scoped by the configured labels", - ) + logger.DebugContext(ctx, "skipping host because it's not scoped by the configured labels") continue } @@ -4420,15 +4396,13 @@ func (svc *MDMAppleCheckinAndCommandService) handleScheduledUpdates( ForScheduledUpdates: true, }) if err != nil { - level.Error(logger).Log( - "msg", "install VPP app post validation", + logger.ErrorContext(ctx, "install VPP app post validation", "err", err, ) continue } - level.Debug(logger).Log( - "msg", "update scheduled", + logger.DebugContext(ctx, "update scheduled", "command_uuid", commandUUID, ) } @@ -4640,7 +4614,8 @@ func (svc *MDMAppleCheckinAndCommandService) handleRefetchDeviceResults(ctx cont return nil, ctxerr.NewWithData(ctx, "device is in lost mode but no EnableLostMode command record found", map[string]interface{}{"host_uuid": host.UUID}) } - level.Debug(svc.logger).Log("msg", "device is in lost mode and EnableLostMode command record found, updating host lock/wipe status", "host_uuid", host.UUID) + svc.logger.DebugContext(ctx, "device is in lost mode and EnableLostMode command record found, updating host lock/wipe status", + "host_uuid", host.UUID) err = svc.ds.SetLockCommandForLostModeCheckin(ctx, host.ID, cmd.CommandUUID) if err != nil { return nil, ctxerr.Wrap(ctx, err, "update host lost mode status on refetch") @@ -4821,7 +4796,7 @@ func SendPushesToPendingDevices( if err := commander.SendNotifications(ctx, enrollmentIDs); err != nil { var apnsErr *apple_mdm.APNSDeliveryError if errors.As(err, &apnsErr) { - level.Info(logger).Log("msg", "failed to send APNs notification to some hosts", "error", apnsErr.Error()) + logger.InfoContext(ctx, "failed to send APNs notification to some hosts", "error", apnsErr.Error()) return nil } @@ -4873,7 +4848,7 @@ func ReconcileAppleDeclarations( } if len(changedHosts) == 0 { - level.Info(logger).Log("msg", "no hosts with changed declarations") + logger.InfoContext(ctx, "no hosts with changed declarations") return nil } @@ -4882,7 +4857,7 @@ func ReconcileAppleDeclarations( return ctxerr.Wrap(ctx, err, "issuing DeclarativeManagement command") } - level.Info(logger).Log("msg", "sent DeclarativeManagement command", "host_number", len(changedHosts)) + logger.InfoContext(ctx, "sent DeclarativeManagement command", "host_number", len(changedHosts)) return nil } @@ -5084,7 +5059,7 @@ func ReconcileAppleProfiles( errorDetail = "This setting couldn't be enforced because the user channel isn't available on iOS and iPadOS hosts." } else { errorDetail = "This setting couldn't be enforced because the user channel doesn't exist for this host. Currently, Fleet creates the user channel for hosts that automatically enroll." - level.Warn(logger).Log("msg", "host does not have a user enrollment, failing profile installation", + logger.WarnContext(ctx, "host does not have a user enrollment, failing profile installation", "host_uuid", p.HostUUID, "profile_uuid", p.ProfileUUID, "profile_identifier", p.ProfileIdentifier) } @@ -5163,7 +5138,7 @@ func ReconcileAppleProfiles( return err } if userEnrollmentID == "" { - level.Warn(logger).Log("msg", "host does not have a user enrollment, cannot remove user scoped profile", + logger.WarnContext(ctx, "host does not have a user enrollment, cannot remove user scoped profile", "host_uuid", p.HostUUID, "profile_uuid", p.ProfileUUID, "profile_identifier", p.ProfileIdentifier) hostProfilesToCleanup = append(hostProfilesToCleanup, p) continue @@ -5251,7 +5226,7 @@ func ReconcileAppleProfiles( } // Find the profiles containing secret variables. - profilesWithSecrets, err := findProfilesWithSecrets(logger, installTargets, profileContents) + profilesWithSecrets, err := findProfilesWithSecrets(ctx, logger, installTargets, profileContents) if err != nil { return err } @@ -5283,9 +5258,9 @@ func ReconcileAppleProfiles( var e *apple_mdm.APNSDeliveryError switch { case errors.As(err, &e): - level.Debug(logger).Log("err", "sending push notifications, profiles still enqueued", "details", err) + logger.DebugContext(ctx, "sending push notifications, profiles still enqueued", "details", err) case err != nil: - level.Error(logger).Log("err", fmt.Sprintf("enqueue command to %s profiles", op), "details", err) + logger.ErrorContext(ctx, fmt.Sprintf("enqueue command to %s profiles", op), "details", err) ch <- remoteResult{err, target.cmdUUID} } } @@ -5340,6 +5315,7 @@ func ReconcileAppleProfiles( } func findProfilesWithSecrets( + ctx context.Context, logger *platformlogging.Logger, installTargets map[string]*cmdTarget, profileContents map[string]mobileconfig.Mobileconfig, @@ -5348,7 +5324,7 @@ func findProfilesWithSecrets( for profUUID := range installTargets { p, ok := profileContents[profUUID] if !ok { // Should never happen - level.Error(logger).Log("msg", "profile content not found in ReconcileAppleProfiles", "profile_uuid", profUUID) + logger.ErrorContext(ctx, "profile content not found in ReconcileAppleProfiles", "profile_uuid", profUUID) continue } profileStr := string(p) @@ -5570,7 +5546,7 @@ func preprocessProfileContents( if ndesConfig == nil { ndesConfig = groupedCAs.NDESSCEP } - level.Debug(logger).Log("msg", "fetching NDES challenge", "host_uuid", hostUUID, "profile_uuid", profUUID) + logger.DebugContext(ctx, "fetching NDES challenge", "host_uuid", hostUUID, "profile_uuid", profUUID) // Insert the SCEP challenge into the profile contents challenge, err := scepConfig.GetNDESSCEPChallenge(ctx, *ndesConfig) if err != nil { @@ -5655,11 +5631,11 @@ func preprocessProfileContents( caName := strings.TrimPrefix(fleetVar, string(fleet.FleetVarSmallstepSCEPChallengePrefix)) ca, ok := smallstepCAs[caName] if !ok { - level.Error(logger).Log("msg", "Smallstep SCEP CA not found. "+ + logger.ErrorContext(ctx, "Smallstep SCEP CA not found. "+ "This error should never happen since we validated/populated CAs earlier", "ca_name", caName) continue } - level.Debug(logger).Log("msg", "fetching Smallstep SCEP challenge", "host_uuid", hostUUID, "profile_uuid", profUUID) + logger.DebugContext(ctx, "fetching Smallstep SCEP challenge", "host_uuid", hostUUID, "profile_uuid", profUUID) challenge, err := scepConfig.GetSmallstepSCEPChallenge(ctx, *ca) if err != nil { detail := fmt.Sprintf("Fleet couldn't populate $FLEET_VAR_%s. %s", fleet.FleetVarSmallstepSCEPChallengePrefix, err.Error()) @@ -5677,7 +5653,7 @@ func preprocessProfileContents( failed = true break fleetVarLoop } - level.Info(logger).Log("msg", "retrieved SCEP challenge from Smallstep", "host_uuid", hostUUID, "profile_uuid", profUUID) + logger.InfoContext(ctx, "retrieved SCEP challenge from Smallstep", "host_uuid", hostUUID, "profile_uuid", profUUID) payload := &fleet.MDMManagedCertificate{ HostUUID: hostUUID, @@ -5771,7 +5747,7 @@ func preprocessProfileContents( caName := strings.TrimPrefix(fleetVar, string(fleet.FleetVarDigiCertDataPrefix)) ca, ok := digiCertCAs[caName] if !ok { - level.Error(logger).Log("msg", "Custom DigiCert CA not found. "+ + logger.ErrorContext(ctx, "Custom DigiCert CA not found. "+ "This error should never happen since we validated/populated CAs earlier", "ca_name", caName) continue } @@ -6120,7 +6096,7 @@ func RenewSCEPCertificates( ) error { renewalDisable, exists := os.LookupEnv("FLEET_MDM_APPLE_SCEP_RENEWAL_DISABLE") if exists && (strings.EqualFold(renewalDisable, "true") || renewalDisable == "1") { - level.Info(logger).Log("msg", "skipping renewal of macOS SCEP certificates as FLEET_MDM_APPLE_SCEP_RENEWAL_DISABLE is set to true") + logger.InfoContext(ctx, "skipping renewal of macOS SCEP certificates as FLEET_MDM_APPLE_SCEP_RENEWAL_DISABLE is set to true") return nil } @@ -6129,12 +6105,12 @@ func RenewSCEPCertificates( return fmt.Errorf("reading app config: %w", err) } if !appConfig.MDM.EnabledAndConfigured { - level.Debug(logger).Log("msg", "skipping renewal of macOS SCEP certificates as MDM is not fully configured") + logger.DebugContext(ctx, "skipping renewal of macOS SCEP certificates as MDM is not fully configured") return nil } if commander == nil { - level.Debug(logger).Log("msg", "skipping renewal of macOS SCEP certificates as apple_mdm.MDMAppleCommander was not provided") + logger.DebugContext(ctx, "skipping renewal of macOS SCEP certificates as apple_mdm.MDMAppleCommander was not provided") return nil } @@ -6145,7 +6121,7 @@ func RenewSCEPCertificates( } if len(certAssociations) == 0 { - level.Debug(logger).Log("msg", "no certs to renew") + logger.DebugContext(ctx, "no certs to renew") return nil } @@ -6231,7 +6207,8 @@ func RenewSCEPCertificates( if idpAccount != nil { email = idpAccount.Email } else { - level.Error(logger).Log("msg", "no IDP account associated with account driven user enrollment host, sending renewal without email", "host_uuid", assoc.HostUUID) + logger.ErrorContext(ctx, "no IDP account associated with account driven user enrollment host, sending renewal without email", + "host_uuid", assoc.HostUUID) } profile, err := apple_mdm.GenerateAccountDrivenEnrollmentProfileMobileconfig( appConfig.OrgInfo.OrgName, @@ -6282,7 +6259,7 @@ func RenewSCEPCertificates( migrationEnrollmentProfile := string(decodedMigrationEnrollmentProfile) if migrationEnrollmentProfile == "" && hasAssocsFromMigration { - level.Debug(logger).Log("msg", "found devices from migration that need SCEP renewals but FLEET_SILENT_MIGRATION_ENROLLMENT_PROFILE is empty") + logger.DebugContext(ctx, "found devices from migration that need SCEP renewals but FLEET_SILENT_MIGRATION_ENROLLMENT_PROFILE is empty") } if migrationEnrollmentProfile != "" && hasAssocsFromMigration { profileBytes := []byte(migrationEnrollmentProfile) @@ -6353,10 +6330,10 @@ func NewMDMAppleDDMService(ds fleet.Datastore, logger *platformlogging.Logger) * // [1]: https://developer.apple.com/documentation/devicemanagement/declarative_management_checkin func (svc *MDMAppleDDMService) DeclarativeManagement(r *mdm.Request, dm *mdm.DeclarativeManagement) ([]byte, error) { if dm == nil { - level.Debug(svc.logger).Log("msg", "ddm request received with nil payload") + svc.logger.DebugContext(r.Context, "ddm request received with nil payload") return nil, nil } - level.Debug(svc.logger).Log("msg", "ddm request received", "endpoint", dm.Endpoint) + svc.logger.DebugContext(r.Context, "ddm request received", "endpoint", dm.Endpoint) if err := svc.ds.InsertMDMAppleDDMRequest(r.Context, dm.Identifier(), dm.Endpoint, dm.Data); err != nil { return nil, ctxerr.Wrap(r.Context, err, "insert ddm request history") @@ -6368,19 +6345,19 @@ func (svc *MDMAppleDDMService) DeclarativeManagement(r *mdm.Request, dm *mdm.Dec switch { case dm.Endpoint == "tokens": - level.Debug(svc.logger).Log("msg", "received tokens request") + svc.logger.DebugContext(r.Context, "received tokens request") return svc.handleTokens(r.Context, dm.Identifier()) case dm.Endpoint == "declaration-items": - level.Debug(svc.logger).Log("msg", "received declaration-items request") + svc.logger.DebugContext(r.Context, "received declaration-items request") return svc.handleDeclarationItems(r.Context, dm.Identifier()) case dm.Endpoint == "status": - level.Debug(svc.logger).Log("msg", "received status request") + svc.logger.DebugContext(r.Context, "received status request") return nil, svc.handleDeclarationStatus(r.Context, dm) case strings.HasPrefix(dm.Endpoint, "declaration/"): - level.Debug(svc.logger).Log("msg", "received declarations request") + svc.logger.DebugContext(r.Context, "received declarations request") return svc.handleDeclarationsResponse(r.Context, dm.Endpoint, dm.Identifier()) default: @@ -6508,7 +6485,7 @@ func (svc *MDMAppleDDMService) handleDeclarationsResponse(ctx context.Context, e if len(parts) != 3 { return nil, nano_service.NewHTTPStatusError(http.StatusBadRequest, ctxerr.Errorf(ctx, "unrecognized declarations endpoint: %s", endpoint)) } - level.Debug(svc.logger).Log("msg", "parsed declarations request", "type", parts[1], "identifier", parts[2]) + svc.logger.DebugContext(ctx, "parsed declarations request", "type", parts[1], "identifier", parts[2]) switch parts[1] { case "activation": @@ -6591,17 +6568,17 @@ func (svc *MDMAppleDDMService) handleDeclarationStatus(ctx context.Context, dm * detail = apple_mdm.FmtDDMError(r.Reasons) case r.Valid == fleet.MDMAppleDeclarationValid: // should be rare/never // The debug messages here can be used to figure out why a DDM profile is stuck in a certain state on a device. - level.Debug(svc.logger).Log("msg", "valid but inactive declaration status", "status", r.Valid, "active", r.Active, "host", - dm.Identifier(), "declaration", r.Identifier) + svc.logger.DebugContext(ctx, "valid but inactive declaration status", + "status", r.Valid, "active", r.Active, "host", dm.Identifier(), "declaration", r.Identifier) status = fleet.MDMDeliveryVerifying case r.Valid == fleet.MDMAppleDeclarationUnknown: // should be rare - level.Debug(svc.logger).Log("msg", "unknown declaration status", "status", r.Valid, "active", r.Active, "host", dm.Identifier(), - "declaration", r.Identifier) + svc.logger.DebugContext(ctx, "unknown declaration status", + "status", r.Valid, "active", r.Active, "host", dm.Identifier(), "declaration", r.Identifier) status = fleet.MDMDeliveryVerifying default: // This should never happen. If we see this happening, we should handle it. - level.Error(svc.logger).Log("msg", "undefined declaration status", "status", r.Valid, "active", r.Active, "host", dm.Identifier(), - "declaration", r.Identifier) + svc.logger.ErrorContext(ctx, "undefined declaration status", + "status", r.Valid, "active", r.Active, "host", dm.Identifier(), "declaration", r.Identifier) status = fleet.MDMDeliveryFailed detail = fmt.Sprintf("undefined declaration status: %s; %s", r.Valid, apple_mdm.FmtDDMError(r.Reasons)) } @@ -7282,10 +7259,10 @@ func EnsureMDMAppleServiceDiscovery(ctx context.Context, ds fleet.Datastore, dep case err != nil: return ctxerr.Wrap(ctx, err, "listing ABM tokens") case len(tokens) == 0: - level.Info(logger).Log("msg", "no ABM tokens found, skipping account driven enrollment service discovery") + logger.InfoContext(ctx, "no ABM tokens found, skipping account driven enrollment service discovery") return nil case len(tokens) > 1: - level.Debug(logger).Log("msg", "multiple ABM tokens found, using the first one for account driven enrollment service discovery") + logger.DebugContext(ctx, "multiple ABM tokens found, using the first one for account driven enrollment service discovery") } orgName := tokens[0].OrganizationName @@ -7293,9 +7270,9 @@ func EnsureMDMAppleServiceDiscovery(ctx context.Context, ds fleet.Datastore, dep if err != nil { switch { case godep.IsServiceDiscoveryNotFound(err): - level.Info(logger).Log("msg", "account driven enrollment profile not found") // proceed to assignment + logger.InfoContext(ctx, "account driven enrollment profile not found") // proceed to assignment case godep.IsServiceDiscoveryNotSupported(err): - level.Info(logger).Log("msg", "account driven enrollment org not supported, skipping assignment") + logger.InfoContext(ctx, "account driven enrollment org not supported, skipping assignment") return nil // skip assignment default: return ctxerr.Wrap(ctx, err, "fetching account driven enrollment profile") // skip assignment @@ -7308,7 +7285,7 @@ func EnsureMDMAppleServiceDiscovery(ctx context.Context, ds fleet.Datastore, dep gotURL = details.MDMServiceDiscoveryURL lastUpdated = details.LastUpdatedTimestamp } - level.Info(logger).Log("msg", "account driven enrollment service discovery url confirmed", "service_discovery_url", gotURL, "last_updated", lastUpdated) + logger.InfoContext(ctx, "account driven enrollment service discovery url confirmed", "service_discovery_url", gotURL, "last_updated", lastUpdated) if gotURL != sdURL { // proced to assignment diff --git a/server/service/mdm.go b/server/service/mdm.go index a595b01571c..2c0f22b68fd 100644 --- a/server/service/mdm.go +++ b/server/service/mdm.go @@ -46,7 +46,6 @@ import ( "github.com/fleetdm/fleet/v4/server/platform/endpointer" "github.com/fleetdm/fleet/v4/server/ptr" "github.com/fleetdm/fleet/v4/server/worker" - "github.com/go-kit/log/level" "github.com/go-sql-driver/mysql" ) @@ -726,7 +725,7 @@ func (svc *Service) GetMDMCommandResults(ctx context.Context, commandUUID string return svc.getDeviceSoftwareMDMCommandResults(ctx, commandUUID) } - level.Debug(svc.logger).Log("msg", "GetMDMCommandResults called with user authentication", "command_uuid", commandUUID, "host_identifier", hostIdentifier) + svc.logger.DebugContext(ctx, "GetMDMCommandResults called with user authentication", "command_uuid", commandUUID, "host_identifier", hostIdentifier) // first, authorize that the user has the right to list hosts if err := svc.authz.Authorize(ctx, &fleet.Host{}, fleet.ActionList); err != nil { @@ -811,7 +810,7 @@ func (svc *Service) GetMDMCommandResults(ctx context.Context, commandUUID string // Get install status for the VPP app installed, err := svc.ds.GetVPPAppInstallStatusByCommandUUID(ctx, commandUUID) if err != nil { - level.Debug(svc.logger).Log("msg", "failed to check if VPP app is installed", "err", err, "command_uuid", commandUUID) + svc.logger.DebugContext(ctx, "failed to check if VPP app is installed", "err", err, "command_uuid", commandUUID) } else { for _, res := range results { if res.RequestType == "InstallApplication" { @@ -847,7 +846,7 @@ func (svc *Service) getMDMCommandResults(ctx context.Context, commandUUID string results = []*fleet.MDMCommandResult{} default: // this should never happen, but just in case - level.Debug(svc.logger).Log("msg", "unknown MDM command platform", "platform", p) + svc.logger.DebugContext(ctx, "unknown MDM command platform", "platform", p) } if err != nil { @@ -905,7 +904,8 @@ func (svc *Service) getHostIdentifierMDMCommandResults(ctx context.Context, comm return nil, ctxerr.Errorf(ctx, "getHostIdentifierMDMCommandResults: unexpected result for host identifier %s", hostIdentifier) case len(hi) > 1: // FIXME: determine what to do in this unexpected case; for now just log it and use the first one. - level.Debug(svc.logger).Log("msg", "getHostIdentifierMDMCommandResults: multiple hosts found for host identifier", "host_identifier", hostIdentifier, "count", len(hi)) + svc.logger.DebugContext(ctx, "getHostIdentifierMDMCommandResults: multiple hosts found for host identifier", + "host_identifier", hostIdentifier, "count", len(hi)) } // authorize that the user can read commands for the host's team @@ -1072,7 +1072,7 @@ func (svc *Service) ListMDMCommands(ctx context.Context, opts *fleet.MDMCommandL } if authzErr != nil { - level.Error(svc.logger).Log("err", "unauthorized to view some team commands", "details", authzErr) + svc.logger.ErrorContext(ctx, "unauthorized to view some team commands", "details", authzErr) // filter-out the teams that the user is not allowed to view allowedResults := make([]*fleet.MDMCommand, 0, len(results)) @@ -3632,7 +3632,7 @@ func (svc *Service) UnenrollMDM(ctx context.Context, hostID uint) error { return ctxerr.Wrap(ctx, err, "unenrolling android host") } default: - level.Debug(svc.logger).Log("msg", "MDM unenrollment requested for host with unknown platform", "host_id", host.ID, "platform", host.Platform) + svc.logger.DebugContext(ctx, "MDM unenrollment requested for host with unknown platform", "host_id", host.ID, "platform", host.Platform) return &fleet.BadRequestError{ Message: "MDM unenrollment is not supported for this host platform", } diff --git a/server/service/microsoft_mdm.go b/server/service/microsoft_mdm.go index 2cf33c908c2..c46d1843e2c 100644 --- a/server/service/microsoft_mdm.go +++ b/server/service/microsoft_mdm.go @@ -33,7 +33,6 @@ import ( "github.com/fleetdm/fleet/v4/server/mdm/microsoft/syncml" "github.com/fleetdm/fleet/v4/server/ptr" "github.com/fleetdm/fleet/v4/server/variables" - "github.com/go-kit/log/level" mysql_driver "github.com/go-sql-driver/mysql" mdm_types "github.com/fleetdm/fleet/v4/server/fleet" @@ -1054,16 +1053,14 @@ func (svc *Service) authBinarySecurityToken(ctx context.Context, authToken *flee } if !hasExpectedAudience { // Log bad audiences here for debugging - level.Error(svc.logger).Log( - "msg", "unexpected token audience in AzureAD Binary Security Token", + svc.logger.ErrorContext(ctx, "unexpected token audience in AzureAD Binary Security Token", "expected_host", expectedURLParsed.Host, "token_audiences", strings.Join(tokenData.Audience, ","), ) return "", "", ctxerr.Errorf(ctx, "token audience is not authorized") } if !slices.Contains(entraTenantIDs, tokenData.TenantID) { - level.Error(svc.logger).Log( - "msg", "unexpected token tenant in AzureAD Binary Security Token", + svc.logger.ErrorContext(ctx, "unexpected token tenant in AzureAD Binary Security Token", "token_tenant", tokenData.TenantID, ) return "", "", ctxerr.New(ctx, "token tenant is not authorized") @@ -1081,8 +1078,7 @@ func (svc *Service) ProcessMDMMicrosoftDiscovery(ctx context.Context, req *fleet // Checking first if Discovery message is valid and returning error if this is not the case if err := req.IsValidDiscoveryMsg(); err != nil { // Log the raw XML request for debugging invalid messages - level.Debug(svc.logger).Log( - "msg", "invalid discover message", + svc.logger.DebugContext(ctx, "invalid discover message", "err", err.Error(), "request_xml", string(req.Raw), ) @@ -1508,7 +1504,7 @@ func (svc *Service) enqueueInstallFleetdCommand(ctx context.Context, deviceID st } if len(secrets) == 0 { - level.Warn(svc.logger).Log("msg", "unable to find a global enroll secret to install fleetd") + svc.logger.WarnContext(ctx, "unable to find a global enroll secret to install fleetd") return nil } @@ -1517,7 +1513,7 @@ func (svc *Service) enqueueInstallFleetdCommand(ctx context.Context, deviceID st // and we'll try again the next time the host checks in fleetdMetadata, err := fleetdbase.GetMetadata() if err != nil { - level.Warn(svc.logger).Log("msg", "unable to get fleetd-base metadata") + svc.logger.WarnContext(ctx, "unable to get fleetd-base metadata") return nil }