From 37e115834ee0e2876bf3ff0fec4a2d3e86618ddb Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 21 Feb 2020 07:52:40 -0800 Subject: [PATCH] cmd/derper: support logging to logtail Signed-off-by: Brad Fitzpatrick --- cmd/derper/derper.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/derper/derper.go b/cmd/derper/derper.go index 4ce529cff..7dd84a86d 100644 --- a/cmd/derper/derper.go +++ b/cmd/derper/derper.go @@ -21,15 +21,17 @@ import ( "tailscale.com/atomicfile" "tailscale.com/derp" "tailscale.com/derp/derphttp" + "tailscale.com/logpolicy" "tailscale.com/types/key" ) var ( - addr = flag.String("a", ":443", "server address") - configPath = flag.String("c", "", "config file path") - certDir = flag.String("certdir", defaultCertDir(), "directory to store LetsEncrypt certs, if addr's port is :443") - hostname = flag.String("hostname", "derp.tailscale.com", "LetsEncrypt host name, if addr's port is :443") - bytesPerSec = flag.Int("mbps", 5, "Mbps (mebibit/s) per-client rate limit; 0 means unlimited") + addr = flag.String("a", ":443", "server address") + configPath = flag.String("c", "", "config file path") + certDir = flag.String("certdir", defaultCertDir(), "directory to store LetsEncrypt certs, if addr's port is :443") + hostname = flag.String("hostname", "derp.tailscale.com", "LetsEncrypt host name, if addr's port is :443") + bytesPerSec = flag.Int("mbps", 5, "Mbps (mebibit/s) per-client rate limit; 0 means unlimited") + logCollection = flag.String("logcollection", "", "If non-empty, logtail collection to log to") ) func defaultCertDir() string { @@ -89,6 +91,12 @@ func writeNewConfig() config { func main() { flag.Parse() + var logPol *logpolicy.Policy + if *logCollection != "" { + logPol = logpolicy.New(*logCollection) + log.SetOutput(logPol.Logtail) + } + cfg := loadConfig() letsEncrypt := false