Skip to content

Logger handler factory for fallback if not bootstrapped #362

Open
@LePips

Description

@LePips

As a maintainer of a package using swift-log, we want to make an implementation such that if the logging system hasn't been bootstrapped by package clients, then our loggers will use some specific log handler (an OS handler implementation in our case).

I think the API itself would be a bit simple on the Loggers itself, but can foresee ambiguity issues with the trailing closure. I admit I'm also unsure about the performance of making the bootstrap checks, but ultra-fast performance isn't a large concern within our package.

struct Logger {
    init(label: String, ifNotBootstrappedFactory: (String) -> any LogHandler)
}

Or, if the LoggingSystem somehow exposed its own, but newly separate and optional, factory instance we would be able to check within the existing local factory inits, just an idea.

let logger = Logger(label: "mylogger") { label in
    if let bootstrapped = LoggingSystem.factory {
        return bootstrapped(label)
    } else {
        return MyLogHandler(label)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions