Skip to content

Commit

Permalink
[FAB-6334] Rename logging.peer option in core.yaml
Browse files Browse the repository at this point in the history
The logging.peer option in core.yaml is unnecessary. It should be
renamed to logging.level so that it can use the same Viper lookup
key as CORE_LOGGING_LEVEL. Note: CORE_LOGGING_LEVEL set as an
environment variable still overrides the value set in core.yaml.

Change-Id: I33887fb49cc7e954de3212c58713bbb7e990bcce
Signed-off-by: Will Lahti <[email protected]>
  • Loading branch information
wlahti committed Sep 28, 2017
1 parent 8998fd9 commit c0aa4a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
4 changes: 2 additions & 2 deletions core/testutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func init() {

// SetupTestLogging setup the logging during test execution
func SetupTestLogging() {
level, err := logging.LogLevel(viper.GetString("logging.peer"))
level, err := logging.LogLevel(viper.GetString("logging.level"))
if err == nil {
// No error, use the setting
logging.SetLevel(level, "main")
logging.SetLevel(level, "server")
logging.SetLevel(level, "peer")
} else {
configLogger.Warningf("Log level not recognized '%s', defaulting to %s: %s", viper.GetString("logging.peer"), logging.ERROR, err)
configLogger.Warningf("Log level not recognized '%s', defaulting to %s: %s", viper.GetString("logging.level"), logging.ERROR, err)
logging.SetLevel(logging.ERROR, "main")
logging.SetLevel(logging.ERROR, "server")
logging.SetLevel(logging.ERROR, "peer")
Expand Down
2 changes: 1 addition & 1 deletion peer/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestSetLogLevelFromViper(t *testing.T) {
},
{
name: "Valid module name",
args: args{module: "peer"},
args: args{module: "level"},
wantErr: false,
},
{
Expand Down
10 changes: 3 additions & 7 deletions peer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ var mainCmd = &cobra.Command{
Use: "peer",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// check for CORE_LOGGING_LEVEL environment variable, which should override
// all other log settings
loggingSpec := viper.GetString("logging_level")

if loggingSpec == "" {
// if CORE_LOGGING_LEVEL not set, use the value for 'peer' from core.yaml
loggingSpec = viper.GetString("logging.peer")
}
// all other log settings. otherwise, this will use the value for from
// core.yaml
loggingSpec := viper.GetString("logging.level")
flogging.InitFromSpec(loggingSpec)

return nil
Expand Down
5 changes: 2 additions & 3 deletions sampleconfig/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ logging:
# 2. The environment variable CORE_LOGGING_LEVEL otherwise applies to
# all peer commands if defined as a non-empty string.
#
# 3. The value of peer that directly follows in this file. It can also
# be set via the environment variable CORE_LOGGING_PEER.
# 3. The value of `level` that directly follows in this file.
#
# If no overall default level is provided via any of the above methods,
# the peer will default to INFO (the value of defaultLevel in
Expand All @@ -35,7 +34,7 @@ logging:
# Default for all modules running within the scope of a peer.
# Note: this value is only used when --logging-level or CORE_LOGGING_LEVEL
# are not set
peer: info
level: info

# The overall default values mentioned above can be overridden for the
# specific components listed in the override section below.
Expand Down

0 comments on commit c0aa4a7

Please sign in to comment.