-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Extensions
Built-in parsers, transformers, and enrichers are registered in package init() functions. To add your own, register factories and build a custom binary — the default ./cmd/log-forwarder entrypoint only includes built-ins.
The full working example lives in examples/custom/main.go.
- Implement the
transform.Transformerinterface:
type Transformer interface {
Transform(line []byte) (transform.Record, error)
}- Register a factory in
init():
func init() {
transform.Register("uppercase_tab", func(cfg config.TransformConfig) (transform.Transformer, error) {
base, err := transform.New(config.TransformConfig{
Type: "tab",
Columns: cfg.Columns,
})
if err != nil {
return nil, err
}
return &uppercaseTab{base: base}, nil
})
}- Wrap or replace behavior in your type:
type uppercaseTab struct {
base transform.Transformer
}
func (u *uppercaseTab) Transform(line []byte) (transform.Record, error) {
record, err := u.base.Transform(line)
if err != nil {
return nil, err
}
if msg, ok := record["message"].(string); ok {
record["message"] = strings.ToUpper(msg)
}
return record, nil
}- Reference the type in config:
transform:
type: uppercase_tab
columns:
- timestamp
- level
- messageThe factory receives the full TransformConfig, so custom transformers can read columns, pattern, and on_error like built-ins.
- Implement the
parser.Parserinterface:
type Parser interface {
Feed(event watcher.LineEvent) ([]parser.Event, error)
Flush() ([]parser.Event, error)
}- Register a factory in
init():
func init() {
parser.Register("my_parser", func(cfg config.ParserConfig) (parser.Parser, error) {
return &myParser{}, nil
})
}- Reference the type in config:
parser:
type: my_parser- Implement the
enrich.Enricherinterface:
type Enricher interface {
Enrich(record transform.Record) transform.Record
}- Register a factory in
init():
func init() {
enrich.Register("region", func(cfg config.EnricherConfig) (enrich.Enricher, error) {
region := cfg.Fields["region"]
if region == "" {
region = "unknown"
}
return ®ionEnricher{region: region}, nil
})
}- Implement enrichment (mutate and return the record):
type regionEnricher struct {
region string
}
func (r *regionEnricher) Enrich(record transform.Record) transform.Record {
record["region"] = r.region
return record
}- Add to config:
enrichers:
- type: region
fields:
region: us-east-1Use fields to pass arbitrary string configuration into your enricher factory.
- Implement the
filter.Predicateinterface:
type Predicate interface {
Match(record transform.Record) bool
}- Register a factory in
init():
func init() {
filter.Register("min_level", func(cfg config.FilterRuleConfig) (filter.Predicate, error) {
return minLevelFilter{min: cfg.Value}, nil
})
}- Reference the type in config:
filter:
match: all
rules:
- type: min_level
value: ERRORThe factory receives the full FilterRuleConfig, so custom filters can read standard fields (value, values, field, …) or you can extend validation for your registered type.
- Implement the
sink.Sinkinterface:
type Sink interface {
Publish(ctx context.Context, payload []byte) error
Close() error
}- Optionally implement
sink.Checkerfor a startup connectivity probe:
type Checker interface {
Check(ctx context.Context) error
}- Register a factory in
init():
func init() {
sink.Register("bigquery", func(cfg config.SinkConfig) (sink.Sink, error) {
project, _ := cfg.Options["project"].(string)
dataset, _ := cfg.Options["dataset"].(string)
return newBigQuerySink(project, dataset)
})
}- Reference the type in config and pass options:
sink:
type: bigquery
options:
project: my-gcp-project
dataset: application_logsThe factory receives the full SinkConfig, so custom sinks can read options and ignore built-in kafka / file / http_noauth blocks.
go build -o bin/log-forwarder-custom ./examples/custom
./bin/log-forwarder-custom -config configs/example.yamlCopy examples/custom/main.go as a starting point for your own entrypoint — it mirrors cmd/log-forwarder/main.go but registers custom types before starting the pipeline.
User guide
- Home
- Installation and First Run
- How It Works
- Filtering Vendor Noise
- Log Forwarder ATC
- Configuration Guide
- Configuration-Reference
- Config-Catalog
- Choosing a Sink
- Spring Boot Logs
- Watermarks and Restarts
- Built-in-Components
- Custom-Extensions
- Monitoring
- Testing
- Docker
- Deployment
- Example Configs
- Troubleshooting
Contributors