Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Remove Logging to Journald only under systemd #251

Merged
merged 1 commit into from May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/titus-darion/main.go
Expand Up @@ -15,7 +15,7 @@ func pingHandler(w http.ResponseWriter, r *http.Request) {
}

func main() {
logsutil.MaybeSetupLoggerIfUnderSystemd()
logsutil.MaybeSetupLoggerIfOnJournaldAvailable()
log.Println("Darion is starting")
r := newMux()
if err := http.ListenAndServe(":8004", r); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/titus-reaper/main.go
Expand Up @@ -18,9 +18,10 @@ func main() {
flag.BoolVar(&debug, "debug", false, "Turn on debug logging")
flag.Parse()

logsutil.MaybeSetupLoggerIfUnderSystemd()
if debug {
log.SetLevel(log.DebugLevel)
} else {
logsutil.MaybeSetupLoggerIfOnJournaldAvailable()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do this only when !debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if you're running with -debug, you're probably running from the console, and not a service?

}
path := os.Getenv("PATH")
if err := os.Setenv("PATH", fmt.Sprintf("%s%s", path, ":/usr/sbin:/sbin:/usr/local/sbin")); err != nil {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Expand Up @@ -14,7 +14,6 @@ require (
github.com/apparentlymart/go-cidr v0.0.0-20170616213631-2bd8b58cf427
github.com/aws/aws-sdk-go v1.19.15
github.com/coreos/go-systemd v0.0.0-20170731111925-d21964639418
github.com/coreos/pkg v0.0.0-20170405072653-099530d80109 // indirect
github.com/cyphar/filepath-securejoin v0.0.0-20190205144030-7efe413b52e1
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea
github.com/docker/distribution v0.0.0-20170303212246-08b06dc02367 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Expand Up @@ -23,8 +23,6 @@ github.com/aws/aws-sdk-go v1.19.15/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/go-systemd v0.0.0-20170731111925-d21964639418 h1:0QH6fTJVDpblGjjozilaO++YRbnQNnTYh3yuFJHH0o8=
github.com/coreos/go-systemd v0.0.0-20170731111925-d21964639418/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20170405072653-099530d80109 h1:8RxHvQFXd1AgM3q7iG92w06tQKiuqpHCNf5lVKs9bbs=
github.com/coreos/pkg v0.0.0-20170405072653-099530d80109/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cyphar/filepath-securejoin v0.0.0-20190205144030-7efe413b52e1 h1:pZmkaGb99St6jJZFIl/d0Q2l2n5/q6VAWcVWEht2RMk=
github.com/cyphar/filepath-securejoin v0.0.0-20190205144030-7efe413b52e1/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
12 changes: 0 additions & 12 deletions logsutil/util_linux.go
Expand Up @@ -3,21 +3,9 @@
package logsutil

import (
"github.com/coreos/go-systemd/util"
log "github.com/sirupsen/logrus"
"github.com/wercker/journalhook"
)

// MaybeSetupLoggerIfUnderSystemd sets up journald logging if running as a systemd unit
func MaybeSetupLoggerIfUnderSystemd() {
if runningFromSystemService, err := util.RunningFromSystemService(); runningFromSystemService {
journalhook.Enable()
} else if err != nil {
log.Error("Error checking if running under systemd unit: ", err)
}

}

// MaybeSetupLoggerIfOnJournaldAvailable sets up journald logging if the system
func MaybeSetupLoggerIfOnJournaldAvailable() {
journalhook.Enable()
Expand Down
5 changes: 0 additions & 5 deletions logsutil/util_unsupported.go
Expand Up @@ -2,11 +2,6 @@

package logsutil

// MaybeSetupLoggerIfUnderSystemd sets up journald logging if running as a systemd unit
func MaybeSetupLoggerIfUnderSystemd() {

}

// MaybeSetupLoggerIfOnJournaldAvailable sets up journald logging if the system
func MaybeSetupLoggerIfOnJournaldAvailable() {
}
90 changes: 0 additions & 90 deletions vendor/github.com/coreos/go-systemd/util/util.go

This file was deleted.

175 changes: 0 additions & 175 deletions vendor/github.com/coreos/go-systemd/util/util_cgo.go

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/github.com/coreos/go-systemd/util/util_stub.go

This file was deleted.