Skip to content

Commit

Permalink
fix keep flag to keep unchanged keys
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Sep 1, 2016
1 parent 012e38a commit 67465fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,41 @@ type HandlerOptions struct {
ValRGB RGB
}

func (h *HandlerOptions) setup() {
h.Skip = make(map[string]struct{})
h.Keep = make(map[string]struct{})
}

func (h *HandlerOptions) shouldShowKey(key string) bool {
if len(h.Keep) != 0 {
_, keep := h.Keep[key]
return keep
if _, keep := h.Keep[key]; keep {
return true
}
}
if len(h.Skip) != 0 {
_, skip := h.Skip[key]
return !skip
if _, skip := h.Skip[key]; skip {
return false
}
}
return true
}

func (h *HandlerOptions) shouldShowUnchanged(key string) bool {
if len(h.Keep) != 0 {
if _, keep := h.Keep[key]; keep {
return true
}
}
return false
}

func (h *HandlerOptions) SetSkip(skip []string) {
if len(h.Keep) != 0 || h.Skip == nil {
h.setup()
if h.Skip == nil {
h.Skip = make(map[string]struct{})
}
for _, key := range skip {
h.Skip[key] = struct{}{}
}
}

func (h *HandlerOptions) SetKeep(keep []string) {
if len(h.Skip) != 0 || h.Keep == nil {
h.setup()
if h.Keep == nil {
h.Keep = make(map[string]struct{})
}
for _, key := range keep {
h.Keep[key] = struct{}{}
Expand Down
2 changes: 1 addition & 1 deletion json_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (h *JSONHandler) joinKVs(skipUnchanged bool, sep string) []string {
}

if skipUnchanged {
if lastV, ok := h.last[k]; ok && lastV == v {
if lastV, ok := h.last[k]; ok && lastV == v && !h.Opts.shouldShowUnchanged(k) {
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion logrus_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (h *LogrusHandler) joinKVs(skipUnchanged bool, sep string) []string {
}

if skipUnchanged {
if lastV, ok := h.last[k]; ok && lastV == v {
if lastV, ok := h.last[k]; ok && lastV == v && !h.Opts.shouldShowUnchanged(k) {
continue
}
}
Expand Down

0 comments on commit 67465fb

Please sign in to comment.