Here is a snippet of module initialization.
type AuthProvider struct {
Name string `json:"-"`
CommonParameters
Azure *AzureIdp `json:"azure,omitempty"`
logger *zap.Logger `json:"-"`
}
// CaddyModule returns the Caddy module information.
func (AuthProvider) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "http.authentication.providers.saml",
New: func() caddy.Module { return new(AuthProvider) },
}
}
// Provision provisions SAML authentication provider
func (m *AuthProvider) Provision(ctx caddy.Context) error {
m.logger = caddy.Log()
m.logger.Debug("provisioning saml plugin")
m.Name = "saml"
return nil
}
After I call caddy.Log()
, I get the default logger. The message I would get is:
{"level":"info","ts":1586945928.2531993,"msg":"provisioning saml plugin"}
As you can see the message does not have module name in it. What is the function to initialize a “named” (plugin) logger, such that it would yield the following?
{"level":"info","ts":1586945928.2531993,"logger":"auth.saml","msg":"provisioning saml plugin"}