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

Make logging optional and update docs #189

Merged
merged 7 commits into from
Dec 5, 2024

Conversation

nervenes
Copy link
Contributor

@nervenes nervenes commented Nov 22, 2024

Hello! 👋 This PR contains a few changes, notably:

  • Updating the README.md to use the new initializer instead of the deprecated one.
  • Add a renamed to the deprecated initializer.
  • Updating the docs to use the simpler initializer.
  • Make the logging parameter on the initializers optional, the motivation for this is in cases the user don't or can't do logging, they don't have to construct a logger and bootstrap the logging system with SwiftLogNoOpLogHandler, so this code:
LoggingSystem.bootstrap(SwiftLogNoOpLogHandler.init)
let serviceGroup = ServiceGroup(
    services: [service],
    cancellationSignals: [.sigint],
    logger: .init(label: "")
)

becomes

let serviceGroup = ServiceGroup(
    services: [service],
    cancellationSignals: [.sigint]
)

and it also allows the user to do logging outside the ServiceGroup without necessarily doing logging within it.

If there is anything to improve, let me know! 😃

thanks dimi and gwynne for helping along the way and answering my questions :)

public var logger: Logger
public var logger: Logger?
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't make this change since this an API break. I think at this point there is no nice way to make this optional anymore sadly.

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 see, I've reverted the changes of making it an optional, with only improved docs and readme examples remaining 👍

Choose a reason for hiding this comment

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

An alternative approach to make the logger in the initializers optional could be to chain the log handler from the passed in optional logger to the stored-property logger:

self.logger = Logger(logger.label ?? "ServiceLifecycle", factory: { _ in logger?.handler ?? SwiftLogNoOpLogHandler() })

@FranzBusch
Copy link
Contributor

Thanks for the change. Let's get this landed!

@FranzBusch FranzBusch enabled auto-merge (squash) December 2, 2024 19:14
@FranzBusch FranzBusch added semver/none No version bump required. and removed semver/none No version bump required. labels Dec 2, 2024
@FranzBusch FranzBusch merged commit 0af4033 into swift-server:main Dec 5, 2024
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none No version bump required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants