Skip to content

Commit

Permalink
Merge "Update logging nomenclature - s/module/logger"
Browse files Browse the repository at this point in the history
  • Loading branch information
sykesm authored and Gerrit Code Review committed Nov 12, 2018
2 parents c49f827 + a3f79a7 commit 859de27
Show file tree
Hide file tree
Showing 31 changed files with 113 additions and 128 deletions.
4 changes: 2 additions & 2 deletions common/flogging/floggingtest/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ func (t *TestingWriter) Sync() error { return nil }

type Option func(r *RecordingCore, l *zap.Logger) *zap.Logger

func Named(moduleName string) Option {
func Named(loggerName string) Option {
return func(r *RecordingCore, l *zap.Logger) *zap.Logger {
return l.Named(moduleName)
return l.Named(loggerName)
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/flogging/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func TestGlobalReset(t *testing.T) {
flogging.Reset()
flogging.Global.SetFormat("json")
err := flogging.Global.ActivateSpec("module=debug")
err := flogging.Global.ActivateSpec("logger=debug")
assert.NoError(t, err)

system, err := flogging.New(flogging.Config{})
Expand Down
2 changes: 1 addition & 1 deletion common/flogging/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func DefaultLevel() string {
// InitFromSpec initializes the logging based on the supplied spec. It is
// exposed externally so that consumers of the flogging package may parse their
// own logging specification. The logging specification has the following form:
// [<module>[,<module>...]=]<level>[:[<module>[,<module>...]=]<level>...]
// [<logger>[,<logger>...]=]<level>[:[<logger>[,<logger>...]=]<logger>...]
func InitFromSpec(spec string) string {
err := Global.ActivateSpec(spec)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions common/flogging/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,37 @@ func TestLegacyInitFromSpec(t *testing.T) {
expectedLevels map[string]string
}{
{
name: "SingleModuleLevel",
name: "SingleLoggerLevel",
spec: "a=info",
expectedResult: "INFO",
expectedLevels: map[string]string{"a": "INFO"},
},
{
name: "MultipleModulesMultipleLevels",
name: "MultipleLoggersMultipleLevels",
spec: "a=info:b=debug",
expectedResult: "INFO",
expectedLevels: map[string]string{"a": "INFO", "b": "DEBUG"},
},
{
name: "MultipleModulesSameLevel",
name: "MultipleLoggersSameLevel",
spec: "a,b=warning",
expectedResult: "INFO",
expectedLevels: map[string]string{"a": "WARN", "b": "WARN"},
},
{
name: "DefaultAndModules",
name: "DefaultAndLoggers",
spec: "ERROR:a=warning",
expectedResult: "ERROR",
expectedLevels: map[string]string{"a": "WARN"},
},
{
name: "ModuleAndDefault",
name: "LoggerAndDefault",
spec: "a=debug:info",
expectedResult: "INFO",
expectedLevels: map[string]string{"a": "DEBUG"},
},
{
name: "EmptyModuleEqualsLevel",
name: "EmptyLoggerEqualsLevel",
spec: "=info",
expectedResult: "INFO",
expectedLevels: map[string]string{},
Expand Down
4 changes: 2 additions & 2 deletions common/flogging/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

// NewZapLogger creates a zap logger around a new zap.Core. The core will use
// the provided encoder and sinks and a level enabler that is associated with
// the provided module name. The logger that is returned will be named the same
// as the module.
// the provided logger name. The logger that is returned will be named the same
// as the logger.
func NewZapLogger(core zapcore.Core, options ...zap.Option) *zap.Logger {
return zap.New(
core,
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/chaincodetest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ chaincode:
logging:
# Default level for all loggers within the chaincode container
level: info
# Override default level for the 'shim' module
# Override default level for the 'shim' logger
shim: warning
# Format for the chaincode container logs
format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'
Expand Down
18 changes: 9 additions & 9 deletions core/chaincode/shim/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func setupChaincodeLogging() {
backendFormatter := logging.NewBackendFormatter(backend, formatter)
logging.SetBackend(backendFormatter).SetLevel(defaultLevel, "")

// set default log level for all modules
// set default log level for all loggers
chaincodeLogLevelString := viper.GetString("chaincode.logging.level")
if chaincodeLogLevelString == "" {
chaincodeLogger.Infof("Chaincode log level not provided; defaulting to: %s", defaultLevel.String())
Expand All @@ -210,7 +210,7 @@ func setupChaincodeLogging() {

initFromSpec(chaincodeLogLevelString, defaultLevel)

// override the log level for the shim logging module - note: if this value is
// override the log level for the shim logger - note: if this value is
// blank or an invalid log level, then the above call to
// `initFromSpec` already set the default log level so no action
// is required here.
Expand Down Expand Up @@ -245,28 +245,28 @@ func initFromSpec(spec string, defaultLevel logging.Level) {
levelAll = defaultLevel // need to reset cause original value was overwritten
}
case 2:
// <module>[,<module>...]=<level>
// <logger,<logger>...]=<level>
levelSingle, err := logging.LogLevel(split[1])
if err != nil {
chaincodeLogger.Warningf("Invalid logging level in '%s' ignored", field)
continue
}

if split[0] == "" {
chaincodeLogger.Warningf("Invalid logging override specification '%s' ignored - no module specified", field)
chaincodeLogger.Warningf("Invalid logging override specification '%s' ignored - no logger specified", field)
} else {
modules := strings.Split(split[0], ",")
for _, module := range modules {
chaincodeLogger.Debugf("Setting logging level for module '%s' to '%s'", module, levelSingle)
logging.SetLevel(levelSingle, module)
loggers := strings.Split(split[0], ",")
for _, logger := range loggers {
chaincodeLogger.Debugf("Setting logging level for logger '%s' to '%s'", logger, levelSingle)
logging.SetLevel(levelSingle, logger)
}
}
default:
chaincodeLogger.Warningf("Invalid logging override '%s' ignored - missing ':'?", field)
}
}

logging.SetLevel(levelAll, "") // set the logging level for all modules
logging.SetLevel(levelAll, "") // set the logging level for all loggers
}

// StartInProc is an entry point for system chaincodes bootstrap. It is not an
Expand Down
14 changes: 2 additions & 12 deletions core/chaincode/shim/shim_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package shim
Expand Down
30 changes: 15 additions & 15 deletions docs/source/commands/peerlogging.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Usage:
peer logging [command]
Available Commands:
getlevel Returns the logging level of the requested module logger.
getlevel Returns the logging level of the requested logger.
getlogspec Returns the active log spec.
revertlevels Reverts the logging spec to the peer's spec at startup.
setlevel Adds the module and log level to the current logging spec.
setlevel Adds the logger and log level to the current logging spec.
setlogspec Sets the logging spec.
Flags:
Expand All @@ -47,10 +47,10 @@ Use "peer logging [command] --help" for more information about a command.

## peer logging getlevel
```
Returns the logging level of the requested module logger. Note: the module name should exactly match the name that is displayed in the logs.
Returns the logging level of the requested logger. Note: the logger name should exactly match the name that is displayed in the logs.
Usage:
peer logging getlevel <module> [flags]
peer logging getlevel <logger> [flags]
Flags:
-h, --help help for getlevel
Expand All @@ -71,10 +71,10 @@ Flags:

## peer logging setlevel
```
Adds the module and log level to the current logging specification.
Adds the logger and log level to the current logging specification.
Usage:
peer logging setlevel <module> <log level> [flags]
peer logging setlevel <logger> <log level> [flags]
Flags:
-h, --help help for setlevel
Expand All @@ -86,12 +86,12 @@ Flags:

Here is an example of the `peer logging getlevel` command:

* To get the log level for module `peer`:
* To get the log level for logger `peer`:

```
peer logging getlevel peer
2018-11-01 14:18:11.276 UTC [cli.logging] getLevel -> INFO 001 Current log level for module 'peer': INFO
2018-11-01 14:18:11.276 UTC [cli.logging] getLevel -> INFO 001 Current log level for logger 'peer': INFO
```

Expand All @@ -112,30 +112,30 @@ Here is an example of the `peer logging getlogspec` command:

Here are some examples of the `peer logging setlevel` command:

* To set the log level for modules matching logger name prefix `gossip` to
* To set the log level for loggers matching logger name prefix `gossip` to
log level `WARNING`:

```
peer logging setlevel gossip warning
2018-11-01 14:21:55.509 UTC [cli.logging] setLevel -> INFO 001 Log level set for module name/prefix 'gossip': WARNING
2018-11-01 14:21:55.509 UTC [cli.logging] setLevel -> INFO 001 Log level set for logger name/prefix 'gossip': WARNING
```

* To set the log level to `ERROR` for only the module that exactly matches the
supplied name, append a period to the module name:
* To set the log level to `ERROR` for only the logger that exactly matches the
supplied name, append a period to the logger name:

```
peer logging setlevel gossip. error
2018-11-01 14:27:33.080 UTC [cli.logging] setLevel -> INFO 001 Log level set for module name/prefix 'gossip.': ERROR
2018-11-01 14:27:33.080 UTC [cli.logging] setLevel -> INFO 001 Log level set for logger name/prefix 'gossip.': ERROR
```

### Set Log Spec Usage

Here is an example of the `peer logging setlogspec` command:

* To set the active logging spec for the peer where modules that begin with
* To set the active logging spec for the peer where loggers that begin with
`gossip` and `msp` are set to log level `WARNING` and the default for all
other modules is log level `INFO`:
other loggers is log level `INFO`:

```
peer logging setlogspec gossip=warning:msp=warning:info
Expand Down
29 changes: 14 additions & 15 deletions docs/source/logging-control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ package if they use the logging methods provided by the ``shim``.
This package supports

- Logging control based on the severity of the message
- Logging control based on the software *module* generating the message
- Logging control based on the software *logger* generating the message
- Different pretty-printing options based on the severity of the
message

All logs are currently directed to ``stderr``. Global and module-level
All logs are currently directed to ``stderr``. Global and logger-level
control of logging by severity is provided for both users and developers.
There are currently no formalized rules for the types of information
provided at each severity level. When submitting bug reports, developers
may want to see full logs down to the DEBUG level.

In pretty-printed logs the logging level is indicated both by color and
by a four-character code, e.g, "ERRO" for ERROR, "DEBU" for DEBUG, etc. In
the logging context a *module* is an arbitrary name (string) given by
the logging context a *logger* is an arbitrary name (string) given by
developers to groups of related messages. In the pretty-printed example
below, the logging modules ``ledgermgmt``, ``kvledger``, and ``peer`` are
below, the loggers ``ledgermgmt``, ``kvledger``, and ``peer`` are
generating logs.

::
Expand All @@ -35,10 +35,9 @@ generating logs.
2018-11-01 15:32:38.357 UTC [peer] func1 -> INFO 006 Auto-detected peer address: 172.24.0.3:7051
2018-11-01 15:32:38.357 UTC [peer] func1 -> INFO 007 Returning peer0.org1.example.com:7051

An arbitrary number of logging modules can be created at runtime,
therefore there is no "master list" of modules, and logging control
constructs can not check whether logging modules actually do or will
exist.
An arbitrary number of loggers can be created at runtime, therefore there is
no "master list" of loggers, and logging control constructs can not check
whether logging loggers actually do or will exist.

Logging specification
----
Expand All @@ -51,7 +50,7 @@ The full logging level specification is of the form

::

[<module>[,<module>...]=]<level>[:[<module>[,<module>...]=]<level>...]
[<logger>[,<logger>...]=]<level>[:[<logger>[,<logger>...]=]<level>...]

Logging severity levels are specified using case-insensitive strings
chosen from
Expand All @@ -62,11 +61,11 @@ chosen from


A logging level by itself is taken as the overall default. Otherwise,
overrides for individual or groups of modules can be specified using the
overrides for individual or groups of loggers can be specified using the

::

<module>[,<module>...]=<level>
<logger>[,<logger>...]=<level>

syntax. Examples of specifications:

Expand Down Expand Up @@ -181,21 +180,21 @@ be set in the
`core.yaml <https://github.com/hyperledger/fabric/blob/master/sampleconfig/core.yaml>`__
file. The key ``chaincode.logging.level`` sets the default level for all
loggers within the Chaincode container. The key ``chaincode.logging.shim``
overrides the default level for the ``shim`` module.
overrides the default level for the ``shim`` logger.

::

# Logging section for the chaincode container
logging:
# Default level for all loggers within the chaincode container
level: info
# Override default level for the 'shim' module
# Override default level for the 'shim' logger
shim: warning

The default logging level can be overridden by using environment
variables. ``CORE_CHAINCODE_LOGGING_LEVEL`` sets the default logging
level for all modules. ``CORE_CHAINCODE_LOGGING_SHIM`` overrides the
level for the ``shim`` module.
level for all loggers. ``CORE_CHAINCODE_LOGGING_SHIM`` overrides the
level for the ``shim`` logger.

Go language chaincodes can also control the logging level of the
chaincode ``shim`` interface through the ``SetLoggingLevel`` API.
Expand Down

0 comments on commit 859de27

Please sign in to comment.