Skip to content

Commit 2eb7961

Browse files
committed
[FAB-9961]Fix docs about Chaincode's log level control
FAB-9961 fixes the document to explain the logging level control within Chaincode container correctly. According to the update in FAB-3232, two environment variables are used. CORE_CHAINCODE_LOGGING_LEVEL sets the default logging level for all modules. CORE_CHAINCODE_LOGGING_SHIM overrides the level for the 'shim' logging module. This CR updates the document to reflect the change above and explain how to set up logging level with core.yaml. This CR also updates environment variables used in comments of fabric/core/chaincode/shim/chaincode.go Change-Id: Ib6e4a24cb932dfd2f341f9d3dc845a8e86c52cb3 Signed-off-by: Yuki Kondo <yuki.kondo@hal.hitachi.com>
1 parent 089760f commit 2eb7961

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

core/chaincode/shim/chaincode.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ func IsEnabledForLogLevel(logLevel string) bool {
165165
}
166166

167167
// SetupChaincodeLogging sets the chaincode logging format and the level
168-
// to the values of CORE_CHAINCODE_LOGFORMAT and CORE_CHAINCODE_LOGLEVEL set
169-
// from core.yaml by chaincode_support.go
168+
// to the values of CORE_CHAINCODE_LOGGING_FORMAT, CORE_CHAINCODE_LOGGING_LEVEL
169+
// and CORE_CHAINCODE_LOGGING_SHIM set from core.yaml by chaincode_support.go
170170
func SetupChaincodeLogging() {
171171
viper.SetEnvPrefix("CORE")
172172
viper.AutomaticEnv()

docs/source/logging-control.rst

+22-8
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,35 @@ control is currently based on the *name* provided when the
177177
logger *name* will appear in all log messages created by the logger. The
178178
``shim`` logs as "shim".
179179

180+
The default logging level for loggers within the Chaincode container can
181+
be set in the
182+
`core.yaml <https://github.com/hyperledger/fabric/blob/master/sampleconfig/core.yaml>`__
183+
file. The key ``chaincode.logging.level`` sets the default level for all
184+
loggers within the Chaincode container. The key ``chaincode.logging.shim``
185+
overrides the default level for the ``shim`` module.
186+
187+
::
188+
189+
# Logging section for the chaincode container
190+
logging:
191+
# Default level for all loggers within the chaincode container
192+
level: info
193+
# Override default level for the 'shim' module
194+
shim: warning
195+
196+
The default logging level can be overridden by using environment
197+
variables. ``CORE_CHAINCODE_LOGGING_LEVEL`` sets the default logging
198+
level for all modules. ``CORE_CHAINCODE_LOGGING_SHIM`` overrides the
199+
level for the ``shim`` module.
200+
180201
Go language chaincodes can also control the logging level of the
181202
chaincode ``shim`` interface through the ``SetLoggingLevel`` API.
182203

183204
``SetLoggingLevel(LoggingLevel level)`` - Control the logging level of
184205
the shim
185206

186-
The default logging level for the shim is ``LogDebug``.
187-
188207
Below is a simple example of how a chaincode might create a private
189-
logging object logging at the ``LogInfo`` level, and also control the
190-
amount of logging provided by the ``shim`` based on an environment
191-
variable.
208+
logging object logging at the ``LogInfo`` level.
192209

193210
::
194211

@@ -197,9 +214,6 @@ variable.
197214
func main() {
198215

199216
logger.SetLevel(shim.LogInfo)
200-
201-
logLevel, _ := shim.LogLevel(os.Getenv("SHIM_LOGGING_LEVEL"))
202-
shim.SetLoggingLevel(logLevel)
203217
...
204218
}
205219

0 commit comments

Comments
 (0)