mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #40124 # Details Implements the proposal in https://docs.google.com/document/d/16qe6oVLKK25nA9GEIPR9Gw_IJ342_wlJRdnWEMmWdas/edit?tab=t.0#heading=h.nlw4agv1xs3g Allows doing e.g. ```go logger.WarnContext(logCtx, "The `team_id` param is deprecated, use `fleet_id` instead", "log_topic", "deprecated-field-names") ``` or ```go if logging.TopicEnabled("deprecated-api-params") { logging.WithLevel(ctx, slog.LevelWarn) logging.WithExtras( ctx, "deprecated_param", queryTagValue, "deprecation_warning", fmt.Sprintf("'%s' is deprecated, use '%s'", queryTagValue, renameTo), ) } ``` Topics can be disabled at the app level, and enabled/disabled at the command-line level. # 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`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [X] Added/updated automated tests - [X] QA'd all new/changed functionality manually No logs have this in prod yet, but I added some manually in a branch and verified that I could enable/disable them via CLI options and env vars, including enabling topics that were disabled on the server. Tested for both server and `fleetctl gitops`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added per-topic logging control to enable or disable logging for specific topics via configuration and CLI flags. * Added context-aware logging methods (ErrorContext, WarnContext, InfoContext, DebugContext) to support contextual logging. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
15 lines
343 B
Go
15 lines
343 B
Go
package str
|
|
|
|
import "strings"
|
|
|
|
func SplitAndTrim(s string, delimiter string, removeEmpty bool) []string {
|
|
parts := strings.Split(s, delimiter)
|
|
cleaned := make([]string, 0, len(parts))
|
|
for _, part := range parts {
|
|
part = strings.TrimSpace(part)
|
|
if !removeEmpty || part != "" {
|
|
cleaned = append(cleaned, part)
|
|
}
|
|
}
|
|
return cleaned
|
|
}
|