Commit 300bdc4d authored by Kegan's avatar Kegan
Browse files

initial logger creation

parent 5d0e71c3
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/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/nullseed/logruseq v0.0.0-20191022112445-275e5c09bb04 h1:hSWuDm9sY4GY36+muhWNgvEaInuFW86PqBaQklU4fZs=
github.com/nullseed/logruseq v0.0.0-20191022112445-275e5c09bb04/go.mod h1:lHVWuxCDdJ0upO1ff+BGEENEv7cs7bPJKHUbED2hh9E=
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.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
package seq
import (
"os"
"github.com/nullseed/logruseq"
"github.com/sirupsen/logrus"
)
type SeqConfig struct {
Endpoint string
Apikey string
Appname string
Seqlevel uint32
Loglevel uint32
}
func NewLogger(config *SeqConfig) *logrus.Entry {
seq_endpoint := config.Endpoint
seq_apikey := config.Apikey
seq_appname := config.Appname
seq_loglevel := config.Seqlevel
var levels []logrus.Level
for i := uint32(0); i <= seq_loglevel; i++ {
levels = append(levels, logrus.Level(i))
}
logrus.SetLevel(logrus.Level(config.Loglevel))
logrus.AddHook(
logruseq.NewSeqHook(
seq_endpoint,
logruseq.OptionAPIKey(seq_apikey),
logruseq.OptionLevels(levels),
),
)
//pid field
pid := os.Getpid()
seqLogger := logrus.WithField("pid", pid)
//app name field
seqLogger = seqLogger.WithField("name", seq_appname)
//hostname field
host, err := os.Hostname()
if err == nil {
seqLogger = seqLogger.WithField("hostname", host)
}
return seqLogger
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment