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

Side by Side Diff: common/logging/config.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/cloudlog/logging.go ('k') | common/logging/exported.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package logging 5 package logging
6 6
7 import ( 7 import (
8 "flag" 8 "flag"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 ) 11 )
12 12
13 // Config is a logging configuration structure. 13 // Config is a logging configuration structure.
14 type Config struct { 14 type Config struct {
15 » Level Level 15 » Level Level
16 » Filter Filter
17 } 16 }
18 17
19 // AddFlags adds common flags to a supplied FlagSet. 18 // AddFlags adds common flags to a supplied FlagSet.
20 func (c *Config) AddFlags(fs *flag.FlagSet) { 19 func (c *Config) AddFlags(fs *flag.FlagSet) {
21 » fs.Var(&c.Level, "log_level", 20 » fs.Var(&c.Level, "log-level",
22 "The logging level. Valid options are: debug, info, warning, err or.") 21 "The logging level. Valid options are: debug, info, warning, err or.")
23 fs.Var(&c.Filter, "log_filter",
24 "Log filter keywords. Can be specified multiple times.")
25 } 22 }
26 23
27 // Set installs a filter-aware logger that wraps the currently-installed Logger 24 // Set installs a logger that wraps the currently-installed Logger and sets
28 // and selectively discards messages based on the logging configuration. 25 // the level via the command-line level flag.
29 func (c *Config) Set(ctx context.Context) context.Context { 26 func (c *Config) Set(ctx context.Context) context.Context {
30 » filterFunc := c.Filter.Get() 27 » return SetLevel(ctx, c.Level)
31 » baseFactory := GetFactory(ctx)
32
33 » ctx = SetLevel(ctx, c.Level)
34 » return SetFactory(ctx, func(ctx context.Context) Logger {
35 » » if value, ok := GetFields(ctx)[FilterOnKey]; ok {
36 » » » if !filterFunc(value) {
37 » » » » return Null()
38 » » » }
39 » » }
40 » » return baseFactory(ctx)
41 » })
42 } 28 }
OLDNEW
« no previous file with comments | « common/logging/cloudlog/logging.go ('k') | common/logging/exported.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698