Documentation
¶
Index ¶
- Variables
- func MustParseLevel(lvlStr string) slog.Level
- func PrintDroppedLogs(ctx context.Context, interval time.Duration, r *RateLimitHandler, ...)
- type ExportHandler
- func (h *ExportHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *ExportHandler) Handle(ctx context.Context, record slog.Record) error
- func (h *ExportHandler) Register(next slog.Handler) slog.Handler
- func (h *ExportHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *ExportHandler) WithGroup(name string) slog.Handler
- type ExportHandlerConfig
- type Handler
- type HandlerFunc
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(format string, a ...any)
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(format string, a ...any)
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Fatalf(msg string, a ...any)
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(format string, a ...any)
- func (l *Logger) IsEnabled(lvl slog.Level) bool
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(format string, a ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithField(k, v string) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- type RateLimitHandler
- func (h *RateLimitHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *RateLimitHandler) Handle(ctx context.Context, record slog.Record) error
- func (h *RateLimitHandler) Register(next slog.Handler) slog.Handler
- func (h *RateLimitHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *RateLimitHandler) WithGroup(name string) slog.Handler
- type RateLimiterHandlerConfig
- type TextHandlerConfig
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultExportHandlerConfig = ExportHandlerConfig{ MinLevel: slog.LevelInfo, }
View Source
var DefaultRateLimitHandlerConfig = RateLimiterHandlerConfig{
Limit: 100,
Burst: 100,
}
View Source
var DefaultTextHandlerConfig = TextHandlerConfig{ Level: MustParseLevel("INFO"), Output: os.Stdout, AddSource: true, }
Functions ¶
func MustParseLevel ¶
func PrintDroppedLogs ¶
func PrintDroppedLogs(ctx context.Context, interval time.Duration, r *RateLimitHandler, printFunc func(level slog.Level, count uint64))
PrintDroppedLogs prints dropped rate limit logs and resets counter to 0.
Types ¶
type ExportHandler ¶
type ExportHandler struct {
// contains filtered or unexported fields
}
ExportHandler export logs to remote.
func NewExportHandler ¶
func NewExportHandler(apiClient components.APIClient, cfg ExportHandlerConfig) *ExportHandler
type ExportHandlerConfig ¶
type Handler ¶
Handler allows to chain multiple handlers. Order of execution is reverse to order of registration meaning first handler is executed last.
func NewTextHandler ¶
func NewTextHandler(cfg TextHandlerConfig) Handler
NewTextHandler returns slog text handler.
type HandlerFunc ¶
type Logger ¶
Logger is a small wrapper around slog with some extra methods for easier migration from logrus.
Example ¶
package main
import (
"context"
"golang.org/x/sync/errgroup"
"os"
"os/signal"
"github.com/castai/logging"
"github.com/castai/logging/components"
)
func main() {
ingestClient, err := components.NewAPIClient(components.Config{
APIBaseURL: "https://api.cast.ai",
APIKey: "<api-key>",
ClusterID: "<cluster-id>",
Component: "castware",
Version: "<version>",
})
if err != nil {
// Handle err ...
return
}
var errg errgroup.Group
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
ingestClientBatchClient := components.NewBatchClient(ingestClient)
errg.Go(func() error {
return ingestClientBatchClient.Run(ctx)
})
errg.Go(func() error {
text := logging.NewTextHandler(logging.DefaultTextHandlerConfig)
export := logging.NewExportHandler(ingestClientBatchClient, logging.DefaultExportHandlerConfig)
log := logging.New(text, export)
// Log logs
log.Infof("debug message with format value %s", "hello")
log.WithField("component", "agent").Errorf("something failed: %v", "unknown")
return nil
})
if err := errg.Wait(); err != nil {
// Hanlde err.
}
}
Output:
type RateLimitHandler ¶
type RateLimitHandler struct {
// contains filtered or unexported fields
}
func NewRateLimitHandler ¶
func NewRateLimitHandler(cfg RateLimiterHandlerConfig) *RateLimitHandler
func (*RateLimitHandler) Register ¶
func (h *RateLimitHandler) Register(next slog.Handler) slog.Handler
Click to show internal directories.
Click to hide internal directories.