Files
tailscale/logtail/logtail_omit.go
James Scott 94fbb03352 logtail: add stateless generic UploadLogs (#20005)
Add UploadLogs, a stateless alternative to NewLogger for callers that
want to push a batch of log entries without the background uploader,
ring buffer, stderr echoing, or network-up gating that a Logger
provides. Entries are encoded, batched up to the server's maximum
upload size, and POSTed synchronously; unlike Logger it does not retry.

The Logger construction is split into a new unexported newLogger so the
connection/encode/upload machinery is shared without starting the
background goroutine.

Log entries are modeled as a generic LogEntry[T] whose Value is inlined
(via go-json-experiment) alongside the reserved "logtail" metadata
member. T may be a struct (or pointer), a map with a string key, or a
jsontext.Value; use jsontext.Value to mix differently-shaped payloads in
a single upload. UploadLogs fills in client_time/proc_id/proc_seq from
the Config where the caller leaves them zero.

Updates tailscale/corp#40908

Change-Id: Idbf23cd0eb8233082fbdb9abed0f6f153b9225ba

Signed-off-by: James Scott <jim@tailscale.com>
2026-06-15 13:27:49 -07:00

64 lines
1.4 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build ts_omit_logtail
package logtail
import (
"context"
"iter"
"time"
tslogger "tailscale.com/types/logger"
"tailscale.com/types/logid"
)
// Noop implementations of everything when ts_omit_logtail is set.
type Logger struct{}
type Buffer any
type Logtail struct {
ClientTime time.Time `json:"client_time,omitzero"`
ProcID uint32 `json:"proc_id,omitzero"`
ProcSeq uint64 `json:"proc_seq,omitzero"`
}
type LogEntry[T any] struct {
Logtail Logtail `json:"logtail,omitzero"`
Value T `json:",inline"`
}
func UploadLogs[T any](ctx context.Context, conf Config, entries iter.Seq[LogEntry[T]]) error {
return nil
}
func Disable() {}
func (*Logger) SetEnabled(enabled bool) {}
func NewLogger(cfg Config, logf tslogger.Logf) *Logger {
return &Logger{}
}
func (*Logger) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (*Logger) Logf(format string, args ...any) {}
func (*Logger) Shutdown(ctx context.Context) error { return nil }
func (*Logger) SetVerbosityLevel(level int) {}
func (l *Logger) SetSockstatsLabel(label any) {}
func (l *Logger) PrivateID() logid.PrivateID { return logid.PrivateID{} }
func (l *Logger) StartFlush() {}
func RegisterLogTap(dst chan<- string) (unregister func()) {
return func() {}
}
func (*Logger) SetNetMon(any) {}