diff --git a/beacon-chain/BUILD.bazel b/beacon-chain/BUILD.bazel index 5462597a5..8a8a3a29f 100644 --- a/beacon-chain/BUILD.bazel +++ b/beacon-chain/BUILD.bazel @@ -19,6 +19,7 @@ go_library( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/featureconfig:go_default_library", + "//shared/journald:go_default_library", "//shared/logutil:go_default_library", "//shared/maxprocs:go_default_library", "//shared/version:go_default_library", @@ -55,6 +56,7 @@ go_image( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/featureconfig:go_default_library", + "//shared/journald:go_default_library", "//shared/logutil:go_default_library", "//shared/version:go_default_library", "@com_github_ethereum_go_ethereum//log:go_default_library", diff --git a/beacon-chain/main.go b/beacon-chain/main.go index fb4da95b4..a48611dbf 100644 --- a/beacon-chain/main.go +++ b/beacon-chain/main.go @@ -15,6 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/debug" "github.com/prysmaticlabs/prysm/shared/featureconfig" + "github.com/prysmaticlabs/prysm/shared/journald" "github.com/prysmaticlabs/prysm/shared/logutil" _ "github.com/prysmaticlabs/prysm/shared/maxprocs" "github.com/prysmaticlabs/prysm/shared/version" @@ -133,6 +134,10 @@ func main() { logrus.SetFormatter(f) case "json": logrus.SetFormatter(&logrus.JSONFormatter{}) + case "journald": + if err := journald.Enable(); err != nil { + return err + } default: return fmt.Errorf("unknown log format %s", format) } diff --git a/deps.bzl b/deps.bzl index 1a96cf8d9..751313411 100644 --- a/deps.bzl +++ b/deps.bzl @@ -3642,3 +3642,9 @@ def prysm_deps(): sum = "h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=", version = "v0.0.0-20191202100458-e7afc7fbc510", ) + go_repository( + name = "com_github_wercker_journalhook", + importpath = "github.com/wercker/journalhook", + sum = "h1:shC1HB1UogxN5Ech3Yqaaxj1X/P656PPCB4RbojIJqc=", + version = "v0.0.0-20180428041537-5d0a5ae867b3", + ) diff --git a/go.mod b/go.mod index 470db2e41..414d43847 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/bazelbuild/rules_go v0.23.2 github.com/cespare/cp v1.1.1 // indirect github.com/confluentinc/confluent-kafka-go v1.4.2 // indirect + github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect github.com/d4l3k/messagediff v1.2.1 github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/deckarep/golang-set v1.7.1 // indirect @@ -106,6 +107,7 @@ require ( github.com/wealdtech/go-eth2-wallet-nd/v2 v2.3.0 github.com/wealdtech/go-eth2-wallet-store-filesystem v1.16.1 github.com/wealdtech/go-eth2-wallet-types/v2 v2.6.0 + github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3 github.com/x-cray/logrus-prefixed-formatter v0.5.2 go.etcd.io/bbolt v1.3.4 go.opencensus.io v0.22.4 diff --git a/go.sum b/go.sum index e1d4b91e1..6078a2d2e 100644 --- a/go.sum +++ b/go.sum @@ -133,6 +133,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU= +github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= @@ -1050,6 +1052,8 @@ github.com/wealdtech/go-eth2-wallet-types/v2 v2.6.0 h1:vBrH5icPPSeb14cdShA7/P2PB github.com/wealdtech/go-eth2-wallet-types/v2 v2.6.0/go.mod h1:X9kYUH/E5YMqFMZ4xL6MJanABUkJGaH/yPZRT2o+yYA= github.com/wealdtech/go-indexer v1.0.0 h1:/S4rfWQbSOnnYmwnvuTVatDibZ8o1s9bmTCHO16XINg= github.com/wealdtech/go-indexer v1.0.0/go.mod h1:u1cjsbsOXsm5jzJDyLmZY7GsrdX8KYXKBXkZcAmk3Zg= +github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3 h1:shC1HB1UogxN5Ech3Yqaaxj1X/P656PPCB4RbojIJqc= +github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= diff --git a/shared/journald/BUILD.bazel b/shared/journald/BUILD.bazel new file mode 100644 index 000000000..4475bf931 --- /dev/null +++ b/shared/journald/BUILD.bazel @@ -0,0 +1,20 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "journald.go", + "journald_linux.go", + ], + importpath = "github.com/prysmaticlabs/prysm/shared/journald", + visibility = ["//visibility:public"], + deps = select({ + "@io_bazel_rules_go//go/platform:android": [ + "@com_github_wercker_journalhook//:go_default_library", + ], + "@io_bazel_rules_go//go/platform:linux": [ + "@com_github_wercker_journalhook//:go_default_library", + ], + "//conditions:default": [], + }), +) diff --git a/shared/journald/journald.go b/shared/journald/journald.go new file mode 100644 index 000000000..702bdc0e1 --- /dev/null +++ b/shared/journald/journald.go @@ -0,0 +1,12 @@ +// +build !linux + +package journald + +import ( + "fmt" +) + +//Enabled returns an error on non-Linux systems +func Enable() error { + return fmt.Errorf("journald is not supported in this platform") +} diff --git a/shared/journald/journald_linux.go b/shared/journald/journald_linux.go new file mode 100644 index 000000000..680a87ae4 --- /dev/null +++ b/shared/journald/journald_linux.go @@ -0,0 +1,13 @@ +// +build linux + +package journald + +import ( + "github.com/wercker/journalhook" +) + +//Enable enables the journald logrus hook +func Enable() error { + journalhook.Enable() + return nil +} diff --git a/slasher/BUILD.bazel b/slasher/BUILD.bazel index 0fe9d868a..41e0bc3cd 100644 --- a/slasher/BUILD.bazel +++ b/slasher/BUILD.bazel @@ -16,6 +16,7 @@ go_library( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/featureconfig:go_default_library", + "//shared/journald:go_default_library", "//shared/logutil:go_default_library", "//shared/version:go_default_library", "//slasher/flags:go_default_library", @@ -57,6 +58,7 @@ go_image( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/featureconfig:go_default_library", + "//shared/journald:go_default_library", "//shared/logutil:go_default_library", "//shared/version:go_default_library", "//slasher/flags:go_default_library", diff --git a/slasher/main.go b/slasher/main.go index eccdbda8f..17d51d690 100644 --- a/slasher/main.go +++ b/slasher/main.go @@ -12,6 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/debug" "github.com/prysmaticlabs/prysm/shared/featureconfig" + "github.com/prysmaticlabs/prysm/shared/journald" "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/shared/version" "github.com/prysmaticlabs/prysm/slasher/flags" @@ -103,6 +104,10 @@ func main() { logrus.SetFormatter(joonix.NewFormatter()) case "json": logrus.SetFormatter(&logrus.JSONFormatter{}) + case "journald": + if err := journald.Enable(); err != nil { + return err + } default: return fmt.Errorf("unknown log format %s", format) } diff --git a/validator/BUILD.bazel b/validator/BUILD.bazel index b99e04c62..e2c6a9f72 100644 --- a/validator/BUILD.bazel +++ b/validator/BUILD.bazel @@ -17,6 +17,7 @@ go_library( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/featureconfig:go_default_library", + "//shared/journald:go_default_library", "//shared/logutil:go_default_library", "//shared/maxprocs:go_default_library", "//shared/params:go_default_library", @@ -58,6 +59,7 @@ go_image( "//shared/cmd:go_default_library", "//shared/debug:go_default_library", "//shared/featureconfig:go_default_library", + "//shared/journald:go_default_library", "//shared/logutil:go_default_library", "//shared/params:go_default_library", "//shared/version:go_default_library", diff --git a/validator/main.go b/validator/main.go index 1f2c76ced..accb1fb24 100644 --- a/validator/main.go +++ b/validator/main.go @@ -17,6 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/debug" "github.com/prysmaticlabs/prysm/shared/featureconfig" + "github.com/prysmaticlabs/prysm/shared/journald" "github.com/prysmaticlabs/prysm/shared/logutil" _ "github.com/prysmaticlabs/prysm/shared/maxprocs" "github.com/prysmaticlabs/prysm/shared/params" @@ -341,6 +342,10 @@ contract in order to activate the validator client`, logrus.SetFormatter(f) case "json": logrus.SetFormatter(&logrus.JSONFormatter{}) + case "journald": + if err := journald.Enable(); err != nil { + return err + } default: return fmt.Errorf("unknown log format %s", format) }