Skip to content

How to set the default logger programatically? #5938

@maxott

Description

@maxott

I'm using Caddy as an embedded component in a service and would like to be able to set at least the default logger to the
zap logger the service has already configured by the time Caddy is started.

The primary reason for that is that setting up the logger in Caddy's config file is missing certain capabilities (primarily related to the encoder). But from management point of view, I want to avoid having to spread/duplicate logger configuration across multiple places (my service & Caddy config).

I guess the easiest place is to "extend" the Log function in logging.go. Being able to set the defaultLogger variable is most likely not going to work as it seems to be "recreated" in setupNewDefault based on its CustomLog settings - which lack what I need.

Or is there already a way to achieve that without any further code changes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions