klbslog

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 21 Imported by: 0

README

klbslog

generic slog handler for klb using rest & fleet

Usage:

    slog.SetDefault(slog.New(klbslog.New(nil, nil)))

Or with options and a parent:

    slog.SetDefault(slog.New(klbslog.New(&slog.HandlerOptions{AddSource: true, Level: slog.LevelDebug}, slog.NewTextHandler(os.Stderr, nil))))

Documentation

Index

Constants

View Source
const (
	PktSetInfo      = 0x0100 // set the process name/etc. {"name":"..."}
	PktLogJson      = 0x0101 // {"time":"2022-11-08T15:28:26.000000000-05:00","level":"INFO","msg":"hello","count":3}
	PktPipeRequest  = 0x0200 // request a pipe from the daemon
	PktPipeResponse = 0x8200 // pipe provided
)

Variables

View Source
var DefaultReceiver = PostReceiver("https://ws.atonline.com/_special/rest/SLog:append")

Functions

func New

func New(opts *slog.HandlerOptions, parent slog.Handler, receiver ...Receiver) slog.Handler

func WithAttributes added in v0.1.7

func WithAttributes(ctx context.Context, args ...any) context.Context

Types

type LogAgent added in v0.3.1

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

func NewLogAgent added in v0.3.3

func NewLogAgent() *LogAgent

func (*LogAgent) GetLogfile added in v0.3.3

func (p *LogAgent) GetLogfile(name string) (*os.File, error)

GetLogfile returns a write-only os.File that can be used when using os/exec to start daemons.

Remember to close the os.File after calling Start.

func (*LogAgent) ProcessLogs added in v0.3.3

func (p *LogAgent) ProcessLogs(logs []map[string]string) error

ProcessLogs sends the logs to the logagent daemon

type Packet added in v0.3.1

type Packet struct {
	Type  uint16
	Flags uint32
	Data  []byte
	FDs   []*os.File // files to be passed (optional)
}

Packet is a wire protocol packet sent to the local logagent

func (*Packet) ReadFrom added in v0.3.1

func (p *Packet) ReadFrom(c io.Reader) error

ReadFrom will receive a packet from the specified unixconn

func (*Packet) SendTo added in v0.3.1

func (p *Packet) SendTo(c io.Writer) error

SendTo will serialize and write the packet to the specified connection. Make sure to lock it so multiple packets aren't sent at the same time.

type PostReceiver added in v0.3.1

type PostReceiver string

func (PostReceiver) ProcessLogs added in v0.3.1

func (p PostReceiver) ProcessLogs(logs []map[string]string) error

type Receiver added in v0.3.1

type Receiver interface {
	ProcessLogs(logs []map[string]string) error
}

type RequestLogHandler added in v0.2.0

type RequestLogHandler struct {
	Handler http.Handler
}

RequestLogHandler is a http handler that will log every requests it handles into slog. It will also update request.Context to return the request information so it will be populated in messages sent via slog.

func (*RequestLogHandler) ServeHTTP added in v0.2.0

func (r *RequestLogHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type SHandler

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

func (*SHandler) Enabled

func (s *SHandler) Enabled(_ context.Context, lvl slog.Level) bool

Enabled returns if SHandler is enabled (note: it always is)

func (*SHandler) Handle

func (s *SHandler) Handle(ctx context.Context, r slog.Record) error

func (*SHandler) WithAttrs

func (s *SHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SHandler) WithGroup

func (s *SHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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