Thanks for following up! If I understanding your concerns correctly, I don’t think there is any reason to think this PR can cause problems.
In the kernel API, log messages are only written to logging connections, not to files or other possible log sinks. So with #30342 a “logger” is just a logging connection. If you create a logging connection, you create a BCLog::Logger instance and if you destroy the logging connection you destroy it.
Before #30342, there is only a single BCLog::Logger instance and all logging connections share it. This PR does not change that. It keeps behavior the same and just adds function parameters so the association between log connections and log sources is explicit, rather than that implicit, and so the more flexible logging enabled by #30342 can be introduced without API changes, binding changes, script and application changes.
How do we deal with ownership of the logger here?
It is owned by the logging connection.
Is it owned by the context?
No.
- should we still expose the
logging_connection_destroy function?
Yes.
- how do users update the logging_connection options? Their handle should be invalid after ownership is passed to the context?
No, a logging connection is just a handle referring to a BCLog::Logger instance. The handle can be used until the connection is closed.
- users may need to create multiple logging connections, e.g. to pass to context-free functions that need logging
No, a logging connection can be passed to different log sources, the log sources do not own the connection.
- managing lifetimes becomes more brittle, i.e. users must ensure
logger is kept alive for the duration of context. This feels like a terrible idea
No, they only need to keep the logging connection open as long as they want to receive logging callbacks. If they don’t want to receive logging callbacks, there is no need for a connection or logger.
but one approach could be to let the static kernel::Context own the loggers, with the implication that connections can be created, but not destroyed (until the application aborts)?
This sounds very kludgy and there should be no need for it. (Having a static context in general seems like a kludge to me and I hope there are plans to get rid of it. There should definitely be no need to use it here.)