Documentation
¶
Index ¶
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug() *zerolog.Event
- func (l *Logger) Error() *zerolog.Event
- func (l *Logger) Fatal() *zerolog.Event
- func (l *Logger) Info() *zerolog.Event
- func (l *Logger) LogFilePath() string
- func (l *Logger) Warn() *zerolog.Event
- func (l *Logger) With(keyvals ...interface{}) *Logger
- func (l *Logger) Zerolog() zerolog.Logger
- type Options
- type OtelOptions
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
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
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 (*Logger) Close ¶ added in v0.3.2
Close flushes pending OTEL batches and closes the file writer. Safe to call multiple times. Safe to call on a Nop logger.
func (*Logger) Fatal ¶ added in v0.3.2
Fatal logs at fatal level and exits. Avoid in Cobra hooks — return errors instead.
func (*Logger) LogFilePath ¶ added in v0.3.2
LogFilePath returns the path to the current log file, or empty string if this is a nop logger.
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.