Logging to a Graylog server
Added the --log-graylog command line argument which sends logs to a Graylog server using GELF/UDP.
This commit is contained in:
parent
aac67dd277
commit
f012a16f05
3 changed files with 12 additions and 6 deletions
|
@ -52,8 +52,6 @@ go build
|
||||||
To Do
|
To Do
|
||||||
------
|
------
|
||||||
|
|
||||||
* Proper logging, work in progress:
|
|
||||||
* Sending logs to... well, Graylog... through CLI switches.
|
|
||||||
* Document command line flags.
|
* Document command line flags.
|
||||||
* Add TLS options (skip checks / specify CA) for the Graylog API.
|
* Add TLS options (skip checks / specify CA) for the Graylog API.
|
||||||
* Read object ownership using `grn_permissions` to preserve privileges on users'
|
* Read object ownership using `grn_permissions` to preserve privileges on users'
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module glgroups
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/gemnasium/logrus-graylog-hook/v3 v3.0.2
|
||||||
github.com/go-ldap/ldap v3.0.3+incompatible
|
github.com/go-ldap/ldap v3.0.3+incompatible
|
||||||
github.com/sirupsen/logrus v1.7.0
|
github.com/sirupsen/logrus v1.7.0
|
||||||
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
|
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
|
||||||
|
|
15
main.go
15
main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
lrh_gl "github.com/gemnasium/logrus-graylog-hook/v3"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
lrh_wr "github.com/sirupsen/logrus/hooks/writer"
|
lrh_wr "github.com/sirupsen/logrus/hooks/writer"
|
||||||
)
|
)
|
||||||
|
@ -22,6 +23,8 @@ type (
|
||||||
logLevel string
|
logLevel string
|
||||||
// A file to write logs into.
|
// A file to write logs into.
|
||||||
logFile string
|
logFile string
|
||||||
|
// Graylog server to send logs to (using GELF/UDP). Format is <hostname>:<port>.
|
||||||
|
logGraylog string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,10 +37,11 @@ var (
|
||||||
func parseCommandLine() cliFlags {
|
func parseCommandLine() cliFlags {
|
||||||
flags := cliFlags{}
|
flags := cliFlags{}
|
||||||
flag.StringVar(&flags.cfgFile, "c", "graylog-groups.yml", "Configuration file.")
|
flag.StringVar(&flags.cfgFile, "c", "graylog-groups.yml", "Configuration file.")
|
||||||
flag.StringVar(&flags.instance, "i", "", "Instance identifier.")
|
flag.StringVar(&flags.instance, "i", "", "Instance identifier")
|
||||||
flag.BoolVar(&flags.quiet, "q", false, "Quiet mode.")
|
flag.BoolVar(&flags.quiet, "q", false, "Quiet mode")
|
||||||
flag.StringVar(&flags.logLevel, "L", "", "Log level.")
|
flag.StringVar(&flags.logLevel, "L", "", "Log level")
|
||||||
flag.StringVar(&flags.logFile, "log-file", "", "Log file.")
|
flag.StringVar(&flags.logFile, "log-file", "", "Log file")
|
||||||
|
flag.StringVar(&flags.logGraylog, "log-graylog", "", "Log to Graylog server (format: <host>:<port>)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
@ -94,6 +98,9 @@ func configureLogging(flags cliFlags) {
|
||||||
if flags.logFile != "" {
|
if flags.logFile != "" {
|
||||||
configureLogFile(flags.logFile)
|
configureLogFile(flags.logFile)
|
||||||
}
|
}
|
||||||
|
if flags.logGraylog != "" {
|
||||||
|
log.Logger.AddHook(lrh_gl.NewGraylogHook(flags.logGraylog, nil))
|
||||||
|
}
|
||||||
if flags.quiet {
|
if flags.quiet {
|
||||||
log.Logger.SetOutput(ioutil.Discard)
|
log.Logger.SetOutput(ioutil.Discard)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue