Skip to content

Commit 2cfb4bf

Browse files
Saad Karimwlahti
authored andcommitted
Add new environment variable for logging spec
A new environment variable (FABRIC_LOGGING_SPEC) has been added, and support for the CORE_LOGGING_LEVEL and log module overrides has been removed. FAB-12487 #done Change-Id: Ia8d72b3b41dd5ac9e37747209fdc51c9014b2811 Signed-off-by: Saad Karim <skarim@us.ibm.com> Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent 174465a commit 2cfb4bf

File tree

10 files changed

+23
-163
lines changed

10 files changed

+23
-163
lines changed

examples/cluster/compose/docker-compose.yaml.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ services:
6262
<<: *logging
6363
environment:
6464
- CORE_PEER_TLS_ENABLED=_TLS_ENABLED_
65-
- CORE_LOGGING_LEVEL=WARNING
6665
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1:7051
6766
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=compose_default
67+
- FABRIC_LOGGING_SPEC=WARNING
6868
volumes:
6969
- /var/run/docker.sock:/var/run/docker.sock
7070
command: peer node start
@@ -173,7 +173,7 @@ services:
173173
environment:
174174
- CORE_PEER_TLS_ENABLED=_TLS_ENABLED_
175175
- CORE_NEXT=true
176-
- CORE_LOGGING_LEVEL=DEBUG
176+
- FABRIC_LOGGING_SPEC=DEBUG
177177
volumes:
178178
- ./nodes/cli:/etc/hyperledger/fabric
179179
- .:/cli

examples/e2e_cli/base/peer-base.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ services:
1313
# bridge network as the peers
1414
# https://docs.docker.com/compose/networking/
1515
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_default
16-
#- CORE_LOGGING_LEVEL=ERROR
17-
- CORE_LOGGING_LEVEL=DEBUG
16+
#- FABRIC_LOGGING_SPEC=ERROR
17+
- FABRIC_LOGGING_SPEC=DEBUG
1818
- CORE_PEER_TLS_ENABLED=true
1919
- CORE_PEER_GOSSIP_USELEADERELECTION=true
2020
- CORE_PEER_GOSSIP_ORGLEADER=false

examples/e2e_cli/docker-compose-cli.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ services:
138138
environment:
139139
- GOPATH=/opt/gopath
140140
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
141-
- CORE_LOGGING_LEVEL=DEBUG
141+
- FABRIC_LOGGING_SPEC=DEBUG
142142
- CORE_PEER_ID=cli
143143
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
144144
- CORE_PEER_LOCALMSPID=Org1MSP

integration/nwo/core_template.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ package nwo
88

99
const DefaultCoreTemplate = `---
1010
logging:
11-
level: info
12-
cauthdsl: warning
13-
gossip: warning
14-
grpc: error
15-
ledger: info
16-
msp: warning
17-
policies: warning
18-
peer:
19-
gossip: warning
2011
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
2112
2213
peer:

integration/nwo/fabricconfig/core.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type Core struct {
2222
}
2323

2424
type Logging struct {
25-
Level string `yaml:"level,omitempty"`
2625
Format string `yaml:"format,omitempty"`
2726

2827
ExtraProperties map[string]interface{} `yaml:",inline,omitempty"`

peer/common/common.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,6 @@ func GetOrdererEndpointOfChain(chainID string, signer msp.SigningIdentity, endor
222222
return bundle.ChannelConfig().OrdererAddresses(), nil
223223
}
224224

225-
// SetLogLevelFromViper sets the log level for 'module' logger to the value in
226-
// core.yaml
227-
func SetLogLevelFromViper(module string) error {
228-
var err error
229-
if module == "" {
230-
return errors.New("log level not set, no module name provided")
231-
}
232-
logLevelFromViper := viper.GetString("logging." + module)
233-
err = CheckLogLevel(logLevelFromViper)
234-
if err != nil {
235-
return err
236-
}
237-
// replace period in module name with forward slash to allow override
238-
// of logging submodules
239-
module = strings.Replace(module, ".", "/", -1)
240-
// only set logging modules that begin with the supplied module name here
241-
err = flogging.SetModuleLevels("^"+module, logLevelFromViper)
242-
return err
243-
}
244-
245225
// CheckLogLevel checks that a given log level string is valid
246226
func CheckLogLevel(level string) error {
247227
if !flogging.IsValidLevel(level) {
@@ -302,12 +282,17 @@ func InitCmd(cmd *cobra.Command, args []string) {
302282
// log settings. if --logging-level is not set, use CORE_LOGGING_LEVEL
303283
// (environment variable takes priority; otherwise, the value set in
304284
// core.yaml)
305-
var loggingSpec string
285+
var loggingLevel string
306286
if viper.GetString("logging_level") != "" {
307-
loggingSpec = viper.GetString("logging_level")
287+
loggingLevel = viper.GetString("logging_level")
308288
} else {
309-
loggingSpec = viper.GetString("logging.level")
289+
loggingLevel = viper.GetString("logging.level")
310290
}
291+
loggingSpec := os.Getenv("FABRIC_LOGGING_SPEC")
292+
if loggingLevel != "" {
293+
mainLogger.Warning("CORE_LOGGING_LEVEL is no longer supported, please use FABRIC_LOGGING_SPEC environment variable.")
294+
}
295+
311296
flogging.Init(flogging.Config{
312297
Format: viper.GetString("logging.format"),
313298
Writer: logOutput,

peer/common/common_test.go

Lines changed: 9 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -107,80 +107,6 @@ func TestSetBCCSPKeystorePath(t *testing.T) {
107107
os.Unsetenv("FABRIC_CFG_PATH")
108108
}
109109

110-
func TestSetLogLevelFromViper(t *testing.T) {
111-
viper.Reset()
112-
cleanup := configtest.SetDevFabricConfigPath(t)
113-
defer cleanup()
114-
115-
common.InitConfig("core")
116-
type args struct {
117-
module string
118-
}
119-
tests := []struct {
120-
name string
121-
args args
122-
wantErr bool
123-
}{
124-
{
125-
name: "Empty module name",
126-
args: args{module: ""},
127-
wantErr: true,
128-
},
129-
{
130-
name: "Invalid module name",
131-
args: args{module: "policy"},
132-
wantErr: true,
133-
},
134-
{
135-
name: "Valid module name",
136-
args: args{module: "cauthdsl"},
137-
wantErr: false,
138-
},
139-
{
140-
name: "Valid module name",
141-
args: args{module: "level"},
142-
wantErr: false,
143-
},
144-
{
145-
name: "Valid module name",
146-
args: args{module: "gossip"},
147-
wantErr: false,
148-
},
149-
{
150-
name: "Valid module name",
151-
args: args{module: "grpc"},
152-
wantErr: false,
153-
},
154-
{
155-
name: "Valid module name",
156-
args: args{module: "msp"},
157-
wantErr: false,
158-
},
159-
{
160-
name: "Valid module name",
161-
args: args{module: "ledger"},
162-
wantErr: false,
163-
},
164-
{
165-
name: "Valid module name",
166-
args: args{module: "policies"},
167-
wantErr: false,
168-
},
169-
{
170-
name: "Valid module name",
171-
args: args{module: "peer.gossip"},
172-
wantErr: false,
173-
},
174-
}
175-
for _, tt := range tests {
176-
t.Run(tt.name, func(t *testing.T) {
177-
if err := common.SetLogLevelFromViper(tt.args.module); (err != nil) != tt.wantErr {
178-
t.Errorf("SetLogLevelFromViper() args = %v error = %v, wantErr %v", tt.args, err, tt.wantErr)
179-
}
180-
})
181-
}
182-
}
183-
184110
func TestCheckLogLevel(t *testing.T) {
185111
type args struct {
186112
level string
@@ -249,6 +175,8 @@ func TestGetDefaultSigner(t *testing.T) {
249175
}
250176

251177
func TestInitCmd(t *testing.T) {
178+
cleanup := configtest.SetDevFabricConfigPath(t)
179+
defer cleanup()
252180
defer viper.Reset()
253181

254182
// test that InitCmd doesn't remove existing loggers from the module levels map
@@ -257,9 +185,15 @@ func TestInitCmd(t *testing.T) {
257185
assert.Equal(t, "error", flogging.Global.Level("test").String())
258186
flogging.MustGetLogger("chaincode")
259187
assert.Equal(t, flogging.Global.DefaultLevel().String(), flogging.Global.Level("chaincode").String())
188+
flogging.MustGetLogger("test.test2")
189+
flogging.SetModuleLevel("test.test2", "warn")
190+
assert.Equal(t, "warn", flogging.Global.Level("test.test2").String())
260191

261-
viper.Set("logging_level", "chaincode=debug")
192+
origEnvValue := os.Getenv("FABRIC_LOGGING_SPEC")
193+
os.Setenv("FABRIC_LOGGING_SPEC", "chaincode=debug:test.test2=fatal")
262194
common.InitCmd(nil, nil)
263195
assert.Equal(t, "debug", flogging.Global.Level("chaincode").String())
264196
assert.Equal(t, "error", flogging.Global.Level("test").String())
197+
assert.Equal(t, "fatal", flogging.Global.Level("test.test2").String())
198+
os.Setenv("FABRIC_LOGGING_SPEC", origEnvValue)
265199
}

peer/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func main() {
4040

4141
mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
4242
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
43+
mainFlags.MarkHidden("logging_level")
4344

4445
mainCmd.AddCommand(version.Cmd())
4546
mainCmd.AddCommand(node.Cmd())

peer/node/start.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import (
6767
"github.com/hyperledger/fabric/gossip/service"
6868
"github.com/hyperledger/fabric/msp"
6969
"github.com/hyperledger/fabric/msp/mgmt"
70-
"github.com/hyperledger/fabric/peer/common"
7170
peergossip "github.com/hyperledger/fabric/peer/gossip"
7271
"github.com/hyperledger/fabric/peer/version"
7372
cb "github.com/hyperledger/fabric/protos/common"
@@ -127,16 +126,6 @@ func serve(args []string) error {
127126
panic("Unsupported msp type " + msp.ProviderTypeToString(mspType))
128127
}
129128

130-
// set the logging level for specific modules defined via environment
131-
// variables or core.yaml
132-
overrideLogModules := []string{"msp", "gossip", "ledger", "cauthdsl", "policies", "grpc", "peer.gossip"}
133-
for _, module := range overrideLogModules {
134-
err := common.SetLogLevelFromViper(module)
135-
if err != nil {
136-
logger.Warningf("Error setting log level for module '%s': %s", module, err.Error())
137-
}
138-
}
139-
140129
// Trace RPCs with the golang.org/x/net/trace package. This was moved out of
141130
// the deliver service connection factory as it has process wide implications
142131
// and was racy with respect to initialization of gRPC clients and servers.

sampleconfig/core.yaml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,6 @@
1010
###############################################################################
1111
logging:
1212

13-
# Default logging levels are specified here.
14-
15-
# Valid logging levels are case-insensitive strings chosen from
16-
17-
# FATAL | PANIC | ERROR | WARNING | INFO | DEBUG
18-
19-
# The overall default logging level can be specified in various ways,
20-
# listed below from strongest to weakest:
21-
#
22-
# 1. The --logging-level=<level> command line option overrides all other
23-
# default specifications.
24-
#
25-
# 2. The environment variable CORE_LOGGING_LEVEL otherwise applies to
26-
# all peer commands if defined as a non-empty string.
27-
#
28-
# 3. The value of `level` that directly follows in this file.
29-
#
30-
# If no overall default level is provided via any of the above methods,
31-
# the peer will default to INFO (the value of defaultLevel in
32-
# common/flogging/logging.go)
33-
34-
# Default for all modules running within the scope of a peer.
35-
# Note: this value is only used when --logging-level or CORE_LOGGING_LEVEL
36-
# are not set
37-
level: info
38-
39-
# The overall default values mentioned above can be overridden for the
40-
# specific components listed in the override section below.
41-
42-
# Override log levels for various peer modules.
43-
cauthdsl: warning
44-
gossip: info
45-
grpc: error
46-
ledger: info
47-
msp: warning
48-
policies: warning
49-
peer:
50-
gossip: warning
51-
5213
# Message format for the peer logs
5314
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
5415

0 commit comments

Comments
 (0)