apple / swift-log

A Logging API for Swift
https://apple.github.io/swift-log/
Apache License 2.0
3.48k stars 286 forks source link

Align .bootstrap() style between SwiftLog and SwiftMetrics #52

Closed ktoso closed 5 years ago

ktoso commented 5 years ago

The two recently accepted by the SSWG API packages both use the "bootstrap at system start style" to select a (logger | metrics) backend.

The Logging API requires:

LoggingSystem.bootstrap(MyLogHandler.init)

so exposing the LogHandler directly.

At the same time we say that "log handler is internal detail, don't worry about it."

The style is similar yet notably different in the metrics API:

MetricsSystem.bootstrap(SelectedMetricsImplementation())

as the SelectedMetricsImplementation often may / will contain more state than only being a function that creates a stateless metric.

Note as well that one can obtain the factory like MetricsSystem.factory which is important in order to implement more advanced features e.g. removing metrics.


I would like to propose re-aligning the style of how one performs bootstrap in both those APIs, so the SSWG APIs have a shared "feel" and meaning to words used -- e.g. that *Handler should never really appear in "user land" unless there is good reasons to.

Proposal:

Another point for this would be that I can definitely imagine using such factory to keep state around such as connections etc, if the logger wanted to send metrics to an external service for gathering etc.

WDYT?

tomerd commented 5 years ago

+1

ktoso commented 5 years ago

Ok, I'm on it then 👍

ktoso commented 5 years ago

I ended up closing the PRs as had no immediate need for them and it would cause some bigger discussions about the "Factory type" which we currently do not need.

We can revisit this if/when someone encounters an use case they can not workaround using Logger.init(label:factory:).