feature/syslog, cmd/tailscaled, logpolicy: add optional --syslog flag
Add a new modular syslog feature providing a tailscaled --syslog flag that sends the daemon's logs to the system syslog daemon instead of stderr, which is useful when running as a daemon without a service manager that captures stderr (e.g. OpenWrt's procd). The feature package registers two new hooks: one to register its flag before flag parsing, and one that tailscaled calls early in main to redirect the standard library's default logger. Because logpolicy later points the default logger at logtail, whose local console copy writes to stderr, logpolicy now also consults the hook and sends its console copy to the same sink (with timestamps disabled, as syslog records its own). The feature is linked by default only on Linux, FreeBSD, and OpenBSD, and can be removed with the ts_omit_syslog build tag. If connecting to the syslog daemon fails at startup, tailscaled logs a warning and continues logging to stderr. Fixes #16270 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I8f3a92d4c1e6b70a5d29e4f61b3c874250a9de13
This commit is contained in:
committed by
Brad Fitzpatrick
parent
def265083b
commit
0433cc6929
+12
-1
@@ -546,7 +546,18 @@ func (opts Options) init(disableLogging bool) (*logtail.Config, *Policy) {
|
||||
// anyway, no need to add one.
|
||||
lflags = 0
|
||||
}
|
||||
console := log.New(stderrWriter{}, "", lflags)
|
||||
var conWriter io.Writer = stderrWriter{}
|
||||
if buildfeatures.HasSyslog {
|
||||
if f, ok := feature.HookLogSink.GetOk(); ok {
|
||||
if w := f(); w != nil {
|
||||
// Logs are being redirected elsewhere (e.g. to syslog,
|
||||
// which records its own timestamps).
|
||||
conWriter = w
|
||||
lflags = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
console := log.New(conWriter, "", lflags)
|
||||
|
||||
var earlyErrBuf bytes.Buffer
|
||||
earlyLogf := func(format string, a ...any) {
|
||||
|
||||
Reference in New Issue
Block a user