feat(surf): serve startup summary, shutdown report and http request log
- serve prints a startup summary on a terminal (version, environment, URL, admin, database host and name, pending migrations, plugins, drivers) and logs it as a 'startup summary' record plus 'listening on <addr>' - on SIGINT/SIGTERM serve drains, prints and logs a shutdown report and returns nil (exit 0), or the drain errors (exit 1) - the request log is on by default under diary component http with request_id; the route pattern, never the path, is logged - lagoon.PendingMigrations, conga.Worker.Stats, diary.HideOnTTY, bonfire.IsTerminal and bonfire.Details back the summary and report
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
package diary
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
@@ -225,6 +226,30 @@ func ApplyGlobals(g bonfire.Globals) {
|
||||
SetVerbosity(g.Verbosity, g.Quiet)
|
||||
}
|
||||
|
||||
type hideOnTTYKey struct{}
|
||||
|
||||
// HideOnTTY marks ctx so that a console channel writing to a terminal skips
|
||||
// the records logged with it (Logger.InfoContext and the like); daily files,
|
||||
// stderr channels and a console that is not a terminal still write them. A
|
||||
// command that has just printed the same facts as a styled block (serve's
|
||||
// startup summary) logs them with it, so a person does not read them twice
|
||||
// while journald and the log files keep them.
|
||||
func HideOnTTY(ctx context.Context) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, hideOnTTYKey{}, true)
|
||||
}
|
||||
|
||||
// hiddenOnTTY reports whether ctx carries the HideOnTTY mark.
|
||||
func hiddenOnTTY(ctx context.Context) bool {
|
||||
if ctx == nil {
|
||||
return false
|
||||
}
|
||||
v, _ := ctx.Value(hideOnTTYKey{}).(bool)
|
||||
return v
|
||||
}
|
||||
|
||||
// Verbosity returns the current verbosity (0 by default).
|
||||
func Verbosity() int {
|
||||
return int(verbosity.Load())
|
||||
|
||||
Reference in New Issue
Block a user