Add logging deets

Matt Holt 2019-10-29 14:26:17 -06:00
parent 2d41b9a3a8
commit 8627ace92b

@ -14,6 +14,7 @@ If you are writing a Caddy 2 module, please let us know in our [forum](https://c
- [Table of Namespaces and Interfaces](#table-of-namespaces-and-interfaces)
- [Module Lifecycle](#module-lifecycle)
- [Provisioning](#provisioning)
- [Logs](#logs)
- [Validating](#validating)
- [Interface guards](#interface-guards)
- [Host Modules](#host-modules)
@ -170,7 +171,21 @@ func (g *Gizmo) Provision(ctx caddy.Context) error {
This is typically where host modules will load their guest/child modules, but it can be used for pretty much anything.
App modules which use this method MUST NOT depend on other apps in the provision phase, since provisioning of apps is done in an arbitrary order.
Provisioning MUST NOT depend on other apps; since provisioning is when modules are loaded. To rely on other app modules, you must wait until after the Provision phase. The provisioning of apps is done in an arbitrary order.
### Logs
If your module emits logs, **do not use `log.Print*()` from the Go standard library**. In other words, do not use Go's global logger. Caddy uses high-performance, highly flexible, structured logging with [zap](https://github.com/uber-go/zap).
Instead, get a logger in your module's Provision method:
```go
func (g *Gizmo) Provision(ctx caddy.Context) error {
g.logger = ctx.Logger(g) // g.logger is a *zap.Logger
}
```
Then you can emit structured, leveled logs using `g.logger`. See the [zap godoc](https://godoc.org/go.uber.org/zap#Logger) for details.
## Validating