Remove lumberjack logger (#257)

* Removed lumberjack from coremain

As is mentioned in 251, this fix removed lumberjack from coremain.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Remove lumberjack from log middleware

As mentioned in 251, lumberjack is not suitable for applications like CoreDNS
so it is removed from the log middleware.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Update log/README.md as lumberjack has been removed

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Adjust default log output from `ioutil.Discard` to `os.Stdout`

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2016-09-16 07:50:16 -07:00
committed by Miek Gieben
parent 1c6dd35b23
commit 953cfc1de4
9 changed files with 7 additions and 254 deletions

View File

@@ -54,26 +54,6 @@ The following place holders are supported:
* `{>opcode}`: query OPCODE
## Log Rotation
If you enable log rotation, log files will be automatically maintained when they get large or old.
You can use rotation by opening a block on your first line, which can be any of the variations
described above:
~~~
log ... {
rotate {
size maxsize
age maxage
keep maxkeep
}
}
~~~
* `maxsize` is the maximum size of a log file in megabytes (MB) before it gets rotated. Default is 100 MB.
* `maxage` is the maximum age of a rotated log file in days, after which it will be deleted. Default is to never delete old files because of age.
* `maxkeep` is the maximum number of rotated log files to keep. Default is to retain all old log files.
## Examples
Log all requests to a file:
@@ -87,14 +67,3 @@ Custom log format:
~~~
log . ../query.log "{proto} Request: {name} {type} {>id}"
~~~
With rotation:
~~~
log query.log {
rotate {
100 # Rotate after 100 MB
age 14 # Keep log files for 14 days
keep 10 # Keep at most 10 log files
}
}

View File

@@ -10,7 +10,6 @@ import (
"github.com/miekg/coredns/middleware/pkg/dnsrecorder"
"github.com/miekg/coredns/middleware/pkg/rcode"
"github.com/miekg/coredns/middleware/pkg/replacer"
"github.com/miekg/coredns/middleware/pkg/roller"
"github.com/miekg/coredns/request"
"github.com/miekg/dns"
@@ -61,7 +60,6 @@ type Rule struct {
OutputFile string
Format string
Log *log.Logger
Roller *roller.LogRoller
}
const (

View File

@@ -7,7 +7,6 @@ import (
"github.com/miekg/coredns/core/dnsserver"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/pkg/roller"
"github.com/hashicorp/go-syslog"
"github.com/mholt/caddy"
@@ -48,13 +47,7 @@ func setup(c *caddy.Controller) error {
if err != nil {
return middleware.Error("log", err)
}
if rules[i].Roller != nil {
file.Close()
rules[i].Roller.Filename = rules[i].OutputFile
writer = rules[i].Roller.GetLogWriter()
} else {
writer = file
}
writer = file
}
rules[i].Log = log.New(writer, "", 0)
@@ -76,33 +69,12 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
for c.Next() {
args := c.RemainingArgs()
var logRoller *roller.LogRoller
if c.NextBlock() {
if c.Val() == "rotate" {
if c.NextArg() {
if c.Val() == "{" {
var err error
logRoller, err = roller.Parse(c)
if err != nil {
return nil, err
}
// This part doesn't allow having something after the rotate block
if c.Next() {
if c.Val() != "}" {
return nil, c.ArgErr()
}
}
}
}
}
}
if len(args) == 0 {
// Nothing specified; use defaults
rules = append(rules, Rule{
NameScope: ".",
OutputFile: DefaultLogFilename,
Format: DefaultLogFormat,
Roller: logRoller,
})
} else if len(args) == 1 {
// Only an output file specified
@@ -110,7 +82,6 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
NameScope: ".",
OutputFile: args[0],
Format: DefaultLogFormat,
Roller: logRoller,
})
} else {
// Name scope, output file, and maybe a format specified
@@ -132,7 +103,6 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
NameScope: dns.Fqdn(args[0]),
OutputFile: args[1],
Format: format,
Roller: logRoller,
})
}
}

View File

@@ -3,8 +3,6 @@ package log
import (
"testing"
"github.com/miekg/coredns/middleware/pkg/roller"
"github.com/mholt/caddy"
)
@@ -64,17 +62,6 @@ func TestLogParse(t *testing.T) {
OutputFile: "log.txt",
Format: "{when}",
}}},
{`log access.log { rotate { size 2 age 10 keep 3 } }`, false, []Rule{{
NameScope: ".",
OutputFile: "access.log",
Format: DefaultLogFormat,
Roller: &roller.LogRoller{
MaxSize: 2,
MaxAge: 10,
MaxBackups: 3,
LocalTime: true,
},
}}},
}
for i, test := range tests {
c := caddy.NewTestController("dns", test.inputLogRules)
@@ -105,32 +92,6 @@ func TestLogParse(t *testing.T) {
t.Errorf("Test %d expected %dth LogRule Format to be %s , but got %s",
i, j, test.expectedLogRules[j].Format, actualLogRule.Format)
}
if actualLogRule.Roller != nil && test.expectedLogRules[j].Roller == nil || actualLogRule.Roller == nil && test.expectedLogRules[j].Roller != nil {
t.Fatalf("Test %d expected %dth LogRule Roller to be %v, but got %v",
i, j, test.expectedLogRules[j].Roller, actualLogRule.Roller)
}
if actualLogRule.Roller != nil && test.expectedLogRules[j].Roller != nil {
if actualLogRule.Roller.Filename != test.expectedLogRules[j].Roller.Filename {
t.Fatalf("Test %d expected %dth LogRule Roller Filename to be %s, but got %s",
i, j, test.expectedLogRules[j].Roller.Filename, actualLogRule.Roller.Filename)
}
if actualLogRule.Roller.MaxAge != test.expectedLogRules[j].Roller.MaxAge {
t.Fatalf("Test %d expected %dth LogRule Roller MaxAge to be %d, but got %d",
i, j, test.expectedLogRules[j].Roller.MaxAge, actualLogRule.Roller.MaxAge)
}
if actualLogRule.Roller.MaxBackups != test.expectedLogRules[j].Roller.MaxBackups {
t.Fatalf("Test %d expected %dth LogRule Roller MaxBackups to be %d, but got %d",
i, j, test.expectedLogRules[j].Roller.MaxBackups, actualLogRule.Roller.MaxBackups)
}
if actualLogRule.Roller.MaxSize != test.expectedLogRules[j].Roller.MaxSize {
t.Fatalf("Test %d expected %dth LogRule Roller MaxSize to be %d, but got %d",
i, j, test.expectedLogRules[j].Roller.MaxSize, actualLogRule.Roller.MaxSize)
}
if actualLogRule.Roller.LocalTime != test.expectedLogRules[j].Roller.LocalTime {
t.Fatalf("Test %d expected %dth LogRule Roller LocalTime to be %t, but got %t",
i, j, test.expectedLogRules[j].Roller.LocalTime, actualLogRule.Roller.LocalTime)
}
}
}
}