-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The syslog logrus hook does not support Windows: https://github.com/sirupsen/logrus/blob/master/hooks/syslog/syslog.go So we have to work around that. While at it, ensure logger initialization errors are really bubbling up, and prevent healthcheck tests from depending on our logger implementation.
- Loading branch information
Showing
7 changed files
with
152 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ builds: | |
goos: | ||
- darwin | ||
- linux | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// +build !windows | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"log/syslog" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
ls "github.com/sirupsen/logrus/hooks/syslog" | ||
"github.com/sirupsen/logrus/hooks/test" | ||
) | ||
|
||
func getOutput(logServer string, logOutput string) (io.Writer, logrus.Hook, error) { | ||
var output io.Writer | ||
var hook logrus.Hook | ||
var err error | ||
|
||
switch logOutput { | ||
case outputStdout: | ||
output = os.Stdout | ||
case outputStderr: | ||
output = os.Stderr | ||
case outputTest: | ||
output = ioutil.Discard | ||
_, hook = test.NewNullLogger() | ||
case outputSyslog: | ||
output = os.Stderr | ||
if logServer == "" { | ||
return nil, nil, fmt.Errorf("syslog output needs a log server (ie. 127.0.0.1:514)") | ||
} | ||
hook, err = ls.NewSyslogHook("udp", logServer, syslog.LOG_INFO, "katafygio") | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to hook syslog output") | ||
} | ||
default: | ||
output = os.Stderr | ||
} | ||
|
||
return output, hook, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build windows | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/sirupsen/logrus/hooks/test" | ||
) | ||
|
||
func getOutput(logServer string, logOutput string) (io.Writer, logrus.Hook, error) { | ||
var output io.Writer | ||
var hook logrus.Hook | ||
|
||
switch logOutput { | ||
case outputStdout: | ||
output = os.Stdout | ||
case outputStderr: | ||
output = os.Stderr | ||
case outputTest: | ||
output = ioutil.Discard | ||
_, hook = test.NewNullLogger() | ||
case outputSyslog: | ||
return nil, nil, fmt.Errorf("Syslog output isn't supported on Windows") | ||
default: | ||
output = os.Stderr | ||
} | ||
|
||
return output, hook, nil | ||
} |