Skip to content

Commit

Permalink
Add filename to log
Browse files Browse the repository at this point in the history
  • Loading branch information
lelvisl committed Jan 10, 2019
1 parent 68364f7 commit 85ecae3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module "github.com/lelvisl/logger"
module github.com/lelvisl/logger

require (
"github.com/bshuster-repo/logrus-logstash-hook" v0.0.0-20180322175230-ea59b04518367f2aafe8cf6d46a7d60605d075ce
"github.com/sirupsen/logrus" v1.0.5
"golang.org/x/crypto" v0.0.0-20180322175230-88942b9c40a4
"golang.org/x/sys" v0.0.0-20180326154331-13d03a9a82fb
github.com/bshuster-repo/logrus-logstash-hook v0.0.0-20180322175230-ea59b04518367f2aafe8cf6d46a7d60605d075ce
github.com/onrik/logrus v0.2.1
github.com/sirupsen/logrus v1.3.0
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc
golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb
)
26 changes: 26 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
github.com/bshuster-repo/logrus-logstash-hook v0.0.0-20180322175230-ea59b04518367f2aafe8cf6d46a7d60605d075ce h1:GH0okCzXIZ3kJQr+D7X1/c4jEK51m1eW7nc63cRE6Yo=
github.com/bshuster-repo/logrus-logstash-hook v0.0.0-20180322175230-ea59b04518367f2aafe8cf6d46a7d60605d075ce/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/onrik/logrus v0.2.1 h1:xEYR+opLvr+hNixPPAimuQppFYHaZ0XLO9hZ2G8WPLI=
github.com/onrik/logrus v0.2.1/go.mod h1:qfe9NeZVAJfIxviw3cYkZo3kvBtLoPRJriAO8zl7qTk=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.0.5 h1:8c8b5uO0zS4X6RPl/sd1ENwSkIc0/H2PaHxE3udaE8I=
github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4 h1:AJCW0rhPjFKEAoValWpqnRKxX8YV0Xvqfw+dOexCTPc=
golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc h1:F5tKCVGp+MUAHhKp5MZtGqAlGX3+oCsiL1Q629FL90M=
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20180326154331-13d03a9a82fb h1:w1eDrzbtlRsu1SyjnZZFUBVuhRN2Rn6DlrHCx9s4ud0=
golang.org/x/sys v0.0.0-20180326154331-13d03a9a82fb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb h1:1w588/yEchbPNpa9sEvOcMZYbWHedwJjg4VOAdDHWHk=
golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7 changes: 5 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package logger

import (
"context"
"os"

"github.com/onrik/logrus/filename"
log "github.com/sirupsen/logrus"
"os"
)

//LogConfig is a configuration for logger
Expand Down Expand Up @@ -63,6 +63,9 @@ func CreateLogger(config LogConfig) *log.Logger {

func initLogger(config LogConfig) *log.Logger {
logger := log.New()
filenameHook := filename.NewHook()
filenameHook.Field = "source" // Customize source field name
logger.AddHook(filenameHook)
switch config.Type {
case "syslog":
logger = initSyslogger(config)
Expand Down

0 comments on commit 85ecae3

Please sign in to comment.