logger

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger added in v0.3.2

type Logger struct {
	// contains filtered or unexported fields
}

Logger wraps zerolog with file rotation and optional OTEL export. Create with New or Nop. Safe for concurrent use after construction.

func New added in v0.3.2

func New(opts Options) (*Logger, error)

New creates a logger with file output and optional OTEL bridge.

OTEL failure is non-fatal: the logger falls back to file-only and the OTEL warning is written to the log file.

func NewWriter added in v0.8.0

func NewWriter(w io.Writer) *Logger

NewWriter creates a logger that writes structured JSON to the given io.Writer. No file rotation, no OTEL bridge — this is the constructor for containerized daemons (clawker-cp, clawkerd) that want their structured logs captured by the container runtime's stdout/stderr collection so `docker logs <container>` shows them.

Use logger.New when you want file-based logging with rotation (that's the CLI/host-side path). Use NewWriter inside containers where the container runtime owns log lifecycle.

func Nop added in v0.3.2

func Nop() *Logger

Nop returns a logger that discards all output.

func (*Logger) Close added in v0.3.2

func (l *Logger) Close() error

Close flushes pending OTEL batches and closes the file writer. Safe to call multiple times. Safe to call on a Nop logger.

func (*Logger) Debug added in v0.3.2

func (l *Logger) Debug() *zerolog.Event

Debug logs at debug level.

func (*Logger) Error added in v0.3.2

func (l *Logger) Error() *zerolog.Event

Error logs at error level.

func (*Logger) Fatal added in v0.3.2

func (l *Logger) Fatal() *zerolog.Event

Fatal logs at fatal level and exits. Avoid in Cobra hooks — return errors instead.

func (*Logger) Info added in v0.3.2

func (l *Logger) Info() *zerolog.Event

Info logs at info level.

func (*Logger) LogFilePath added in v0.3.2

func (l *Logger) LogFilePath() string

LogFilePath returns the path to the current log file, or empty string if this is a nop logger.

func (*Logger) Warn added in v0.3.2

func (l *Logger) Warn() *zerolog.Event

Warn logs at warn level.

func (*Logger) With added in v0.3.2

func (l *Logger) With(keyvals ...interface{}) *Logger

With returns a new Logger with additional context fields. Use this instead of per-call field injection for recurring context like project or agent.

projectLog := log.With("project", "foo", "agent", "bar")
projectLog.Info().Msg("started")

func (*Logger) Zerolog added in v0.3.2

func (l *Logger) Zerolog() zerolog.Logger

Zerolog returns the underlying zerolog.Logger for interop with libraries that accept one directly.

type Options added in v0.1.6

type Options struct {
	// LogsDir is the directory for log files. Required for file logging.
	LogsDir string

	// Filename overrides the log file name within LogsDir.
	// Defaults to "clawker.log" when empty.
	Filename string

	// File rotation settings.
	MaxSizeMB  int  // default: 50
	MaxAgeDays int  // default: 7
	MaxBackups int  // default: 3
	Compress   bool // default: true

	// Otel configures the OTEL zerolog bridge. Nil disables OTEL export.
	Otel *OtelOptions

	// EchoStdout mirrors every record to os.Stdout in addition to the
	// file (and OTEL bridge if configured). Intended for containerized
	// daemons whose structured logs should also surface in
	// `docker logs <container>`; host-side CLI logging leaves this off.
	EchoStdout bool
}

Options configures the logger.

type OtelOptions added in v0.3.2

type OtelOptions struct {
	Endpoint       string        // e.g. "localhost:4317"
	Insecure       bool          // default: true (local collector)
	Timeout        time.Duration // export timeout
	MaxQueueSize   int           // batch processor queue size
	ExportInterval time.Duration // batch export interval

	// ServiceName stamps `service.name` on the Resource attached to every
	// emitted log record. Required when the collector routes on this
	// attribute (routing/trusted, routing/untrusted in otel-config.yaml).
	// Empty leaves the SDK default ("unknown_service:<binary>") which is
	// dropped silently at the routing connector. Callers: "clawker-cli"
	// (host CLI), "clawker-cp" (control plane).
	ServiceName string

	// mTLS configuration. Two mutually-exclusive shapes:
	//
	//   - File-path triple (CACertFile + ClientCertFile + ClientKeyFile).
	//     The exporter reads PEM material from disk at New time. No
	//     in-tree consumer today — clawker-cp uses the TLSConfig path
	//     below, clawker-cli runs Insecure=true on the untrusted otlp
	//     receiver (CLI leaves chain to the CLI root, not the infra
	//     intermediate, so they cannot complete the otlp/infra
	//     handshake), and Envoy/CoreDNS read their bind-mounted PEM via
	//     their own native config (not this struct). Shape preserved
	//     for any future on-disk-cert consumer. If any one of the three
	//     is set, all three must be set.
	//
	//   - In-process tls.Config. The exporter is given a fully-formed
	//     *tls.Config (typically built by
	//     internal/controlplane/otelcerts.Service.LoadTLSConfig with a
	//     GetClientCertificate hook that re-mints on every handshake).
	//     Used by the clawker-cp daemon's own OTel exporter so the leaf
	//     never lands on disk and rotation matches the connection
	//     lifecycle.
	//
	// At most one shape may be set. Insecure is ignored when either is
	// populated.
	CACertFile     string
	ClientCertFile string
	ClientKeyFile  string

	// TLSConfig is the in-process counterpart to the file-path triple.
	// When non-nil, the exporter uses it directly and the file-path
	// fields are not consulted. Construction is the caller's
	// responsibility — see internal/controlplane/otelcerts for the
	// trusted-lane wiring used by clawker-cp.
	TLSConfig *tls.Config
}

OtelOptions configures the OTLP/gRPC log exporter. The transport is gRPC because the collector's trusted-infra receiver speaks gRPC only — an HTTP exporter hits it with the wrong content-type and the receiver returns 415 Unsupported Media Type, silently dropping every record. See newOtelProvider for the receiver-side rationale.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL