Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building and passing tests #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/xaionaro-go/logrustash

go 1.22

require github.com/sirupsen/logrus v1.9.3

require (
github.com/xaionaro-go/goautosocket v0.0.0-20240803221104-cef7f165571a
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xaionaro-go/goautosocket v0.0.0-20240803221104-cef7f165571a h1:nnSVcn4e9TkQ5GuN/MoeET18gSYudJJMtlKXFRHvVjQ=
github.com/xaionaro-go/goautosocket v0.0.0-20240803221104-cef7f165571a/go.mod h1:7X2d4ohzI2SqqM/dNgIlBx3hUl6dB6clspwt+9c9IqA=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
19 changes: 14 additions & 5 deletions logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/sirupsen/logrus"
"github.com/teh-cmc/goautosocket"
gas "github.com/xaionaro-go/goautosocket"
)

// Hook represents a connection to a Logstash instance
Expand Down Expand Up @@ -73,7 +73,16 @@ func NewAsyncHookWithFields(protocol, address, appName string, alwaysSentFields
// NewHookWithFieldsAndPrefix creates a new hook to a Logstash instance, which listens on
// `protocol`://`address`. alwaysSentFields will be sent with every log entry. prefix is used to select fields to filter.
func NewHookWithFieldsAndPrefix(protocol, address, appName string, alwaysSentFields logrus.Fields, prefix string) (*Hook, error) {
conn, err := gas.Dial(protocol, address)
var (
conn net.Conn
err error
)
switch protocol {
case "tcp":
conn, err = gas.Dial("tcp", address)
default:
conn, err = net.Dial(protocol, address)
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -110,7 +119,7 @@ func NewAsyncHookWithFieldsAndConn(conn net.Conn, appName string, alwaysSentFiel
return NewAsyncHookWithFieldsAndConnAndPrefix(conn, appName, alwaysSentFields, "")
}

//NewHookWithFieldsAndConnAndPrefix creates a new hook to a Logstash instance using the suppolied connection and prefix.
// NewHookWithFieldsAndConnAndPrefix creates a new hook to a Logstash instance using the suppolied connection and prefix.
func NewHookWithFieldsAndConnAndPrefix(conn net.Conn, appName string, alwaysSentFields logrus.Fields, prefix string) (*Hook, error) {
return &Hook{conn: conn, appName: appName, alwaysSentFields: alwaysSentFields, hookOnlyPrefix: prefix}, nil
}
Expand Down Expand Up @@ -172,12 +181,12 @@ func (h *Hook) filterHookOnly(entry *logrus.Entry) {

}

//WithPrefix sets a prefix filter to use in all subsequent logging
// WithPrefix sets a prefix filter to use in all subsequent logging
func (h *Hook) WithPrefix(prefix string) {
h.hookOnlyPrefix = prefix
}

//WithField add field with value that will be sent with each message
// WithField add field with value that will be sent with each message
func (h *Hook) WithField(key string, value interface{}) {
h.alwaysSentFields[key] = value
}
Expand Down
2 changes: 1 addition & 1 deletion logstash_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestLogstashFormatter(t *testing.T) {
{"abc", "type"},
{"msg", "message"},
{"info", "level"},
{"Get http://example.com: The error", "error"},
{`Get "http://example.com": The error`, "error"},
// substituted fields
{"def", "fields.message"},
{"ijk", "fields.level"},
Expand Down