Skip to content

Commit

Permalink
Add method to set fluentbit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
bathina2 committed Sep 18, 2024
1 parent 875333f commit 8292e7a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"io"
"net/url"
"os"
"strings"
"time"
Expand Down Expand Up @@ -32,6 +33,12 @@ const (
LevelEnvName = "LOG_LEVEL"
)

var (
ErrEndpointNotSet = errors.New("fluentbit endpoint not set")
ErrPathSet = errors.New("fluentbit endpoint path is set")
ErrNonTCPEndpoint = errors.New("fluentbit endpoint scheme must be tcp")
)

// OutputSink describes the current output sink.
type OutputSink uint8

Expand Down Expand Up @@ -79,6 +86,22 @@ func SetOutput(sink OutputSink) error {
}
}

// SetFluenbitOutput sets the fluentbit output
func SetFluentbitOutput(url *url.URL) error {
if url == nil {
return ErrEndpointNotSet
}
if url.Scheme != "tcp" {
return ErrNonTCPEndpoint
}
if url.Path != "" {
return ErrPathSet
}
hook := NewFluentbitHook(url.Host)
log.AddHook(hook)
return nil
}

var envVarFields field.Fields

// initEnvVarFields populates envVarFields with values from the host's environment.
Expand Down

0 comments on commit 8292e7a

Please sign in to comment.