Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: common/logging/filter.go

Issue 1622553005: Remove log filtering and add stringsetflag. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: error on empty Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « common/logging/fields_test.go ('k') | common/logging/gologger/logger.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package logging
6
7 import (
8 "flag"
9 "strings"
10 )
11
12 const (
13 // FilterOnAll is a Filter value that, when included in a Filter, causes it to
14 // display all log messages.
15 FilterOnAll = "all"
16
17 // FilterOnKey is a log field key whose value specifies the context's fi lter.
18 FilterOnKey = "_filterOn"
19 )
20
21 // Filter is a configurable list of strings to filter on, when the 'filterOn'
22 // property is supplied.
23 type Filter []string
24
25 var _ flag.Value = (*Filter)(nil)
26
27 // Set implements flag.Value.
28 func (f *Filter) Set(v string) error {
29 if len(v) > 0 {
30 *f = append(*f, v)
31 }
32 return nil
33 }
34
35 // String implements flag.Value.
36 func (f *Filter) String() string {
37 return strings.Join([]string(*f), ",")
38 }
39
40 // Get returns a filter function that returns true if the Filter passes the
41 // supplied log flags.
42 func (f Filter) Get() func(interface{}) bool {
43 filterMap := make(map[string]bool)
44 for _, filter := range f {
45 if filter == FilterOnAll {
46 filterMap = nil
47 break
48 }
49 filterMap[filter] = true
50 }
51
52 return func(filterOn interface{}) bool {
53 if filterMap == nil || filterOn == nil {
54 return true
55 }
56
57 switch t := filterOn.(type) {
58 case string:
59 _, ok := filterMap[t]
60 return ok
61
62 default:
63 return true
64 }
65 }
66 }
OLDNEW
« no previous file with comments | « common/logging/fields_test.go ('k') | common/logging/gologger/logger.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698