Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overwrite multislogger.Logger memory rather than reassigning pointer #1578

Merged

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Feb 2, 2024

Noticed that some logs in main func were not getting shipped. When adding a handler we can overwrite the the memory address of the multslogger.Logger to make handlers propagate to previously assigned Loggers.

@James-Pickett James-Pickett force-pushed the james/reset-slogger-after-add-handler branch from 4ed228a to 3b0caf8 Compare February 2, 2024 18:06
@James-Pickett James-Pickett changed the title reset slogger in main after adding handler overwrite multislogger.Logger memory rather than reassigning pointer Feb 2, 2024
directionless
directionless previously approved these changes Feb 2, 2024
Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

seems okay to try

@@ -51,7 +51,7 @@ func New(stores map[storage.Store]types.KVStore, flags types.Flags, db *bbolt.DB
}

if k.slogger != nil {
k.slogger.Logger = k.slogger.Logger.With("launcher_run_id", k.launcherRunId)
*k.slogger.Logger = *k.slogger.Logger.With("launcher_run_id", k.launcherRunId)
Copy link
Contributor

Choose a reason for hiding this comment

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

This spot feels like it breaks an abstraction. Somehow it feels wrong for knapsack to be reaching into slogger.Logger. But 🤷 not the end of the world

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, it's a weird spot. Knapsack needs access to the multislogger to be able to add handlers. We also want the launcher_run_id to be universally included in all logs ..... hmm maybe multislogger should just add it, then knapsack can stop reaching in there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this down to the multislogger, now knapsack is staying in it's lane and not reaching down into multislogger's guts

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

LGTM

@James-Pickett James-Pickett added this pull request to the merge queue Feb 5, 2024
Merged via the queue into kolide:main with commit cc3f2e8 Feb 5, 2024
26 checks passed
@James-Pickett James-Pickett deleted the james/reset-slogger-after-add-handler branch February 5, 2024 16:42
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.

3 participants