diff options
author | 2018-07-19 15:16:35 +0100 | |
---|---|---|
committer | 2018-07-19 07:16:35 -0700 | |
commit | c69bed726b4a7b8726833e009ed6dd70a74f0dec (patch) | |
tree | 1adba483932317e2f91dc1d77f644fb578a1fb8f | |
parent | 6621931620e65ef6b4d88ca119eb5a0eaa16fe58 (diff) | |
download | coredns-c69bed726b4a7b8726833e009ed6dd70a74f0dec.tar.gz coredns-c69bed726b4a7b8726833e009ed6dd70a74f0dec.tar.zst coredns-c69bed726b4a7b8726833e009ed6dd70a74f0dec.zip |
plugin/hosts: add log.Debug (#1985)
Logs the amount of entries we parsed after every parse, but only when
debug is loaded.
Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r-- | plugin/hosts/hostsfile.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/plugin/hosts/hostsfile.go b/plugin/hosts/hostsfile.go index 4b912b17c..1d87f82f7 100644 --- a/plugin/hosts/hostsfile.go +++ b/plugin/hosts/hostsfile.go @@ -54,6 +54,22 @@ func newHostsMap() *hostsMap { } } +// Len returns the total number of addresses in the hostmap, this includes +// V4/V6 and any reverse addresses. +func (h *hostsMap) Len() int { + l := 0 + for _, v4 := range h.byNameV4 { + l += len(v4) + } + for _, v6 := range h.byNameV6 { + l += len(v6) + } + for _, a := range h.byAddr { + l += len(a) + } + return l +} + // Hostsfile contains known host entries. type Hostsfile struct { sync.RWMutex @@ -111,6 +127,8 @@ func (h *Hostsfile) initInline(inline []string) { func (h *Hostsfile) parseReader(r io.Reader) { h.hmap = h.parse(r, h.inline) + + log.Debugf("Parsed hosts file into %d entries", h.hmap.Len()) } // Parse reads the hostsfile and populates the byName and byAddr maps. |