middleware/{log,errors}: output everything to stdout (#684)

Limit the options in both errors and log middleware, just output to
stdout and let someone else (journald,docker) care about where to route
the logs. This removes syslog and logging to a file.

Fixes #573 #602
This commit is contained in:
Miek Gieben
2017-05-31 20:28:53 +01:00
committed by GitHub
parent 6c774782e0
commit e261ac1a6e
9 changed files with 49 additions and 186 deletions

View File

@@ -1,7 +1,7 @@
package log
import (
"io"
"fmt"
"log"
"os"
@@ -9,7 +9,6 @@ import (
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/middleware/pkg/response"
"github.com/hashicorp/go-syslog"
"github.com/mholt/caddy"
"github.com/miekg/dns"
)
@@ -30,25 +29,10 @@ func setup(c *caddy.Controller) error {
// Open the log files for writing when the server starts
c.OnStartup(func() error {
for i := 0; i < len(rules); i++ {
var err error
var writer io.Writer
if rules[i].OutputFile == "stdout" {
writer = os.Stdout
} else if rules[i].OutputFile == "stderr" {
writer = os.Stderr
} else if rules[i].OutputFile == "syslog" {
writer, err = gsyslog.NewLogger(gsyslog.LOG_INFO, "LOCAL0", "coredns")
if err != nil {
return middleware.Error("log", err)
}
} else {
var file *os.File
file, err = os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
return middleware.Error("log", err)
}
writer = file
// We only support stdout
writer := os.Stdout
if rules[i].OutputFile != "stdout" {
return middleware.Error("log", fmt.Errorf("invalid log file: %s", rules[i].OutputFile))
}
rules[i].Log = log.New(writer, "", 0)
@@ -78,7 +62,7 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
Format: DefaultLogFormat,
})
} else if len(args) == 1 {
// Only an output file specified
// Only an output file specified.
rules = append(rules, Rule{
NameScope: ".",
OutputFile: args[0],