Skip to content

Commit 890bb2f

Browse files
Brett LoganBrett Logan
authored andcommitted
[FAB-15658] Update doc for Gologging
Removed references for the shim logger from the Doc. Replaced with a statement putting the onus of implementing logging on the chaincode developer. Signed-off-by: Brett Logan <Brett.T.Logan@ibm.com> Change-Id: I160354a867f0d430142725e10da96c94b142e50c
1 parent d439bb3 commit 890bb2f

File tree

1 file changed

+18
-115
lines changed

1 file changed

+18
-115
lines changed

docs/source/logging-control.rst

Lines changed: 18 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -91,130 +91,33 @@ to print the logs in a human-readable console format. It can be also set to
9191
``json`` to output logs in JSON format.
9292

9393

94-
Go chaincodes
95-
-------------
94+
Chaincode
95+
---------
9696

97-
The standard mechanism to log within a chaincode application is to
98-
integrate with the logging transport exposed to each chaincode instance
99-
via the peer. The chaincode ``shim`` package provides APIs that allow a
100-
chaincode to create and manage logging objects whose logs will be
101-
formatted and interleaved consistently with the ``shim`` logs.
97+
**Chaincode logging is the responsibility of the chaincode developer.**
10298

103-
As independently executed programs, user-provided chaincodes may
104-
technically also produce output on stdout/stderr. While naturally useful
105-
for "devmode", these channels are normally disabled on a production
106-
network to mitigate abuse from broken or malicious code. However, it is
107-
possible to enable this output even for peer-managed containers (e.g.
108-
"netmode") on a per-peer basis via the
109-
CORE\_VM\_DOCKER\_ATTACHSTDOUT=true configuration option.
99+
As independently executed programs, user-provided chaincodes may technically
100+
also produce output on stdout/stderr. While naturally useful for “devmode”,
101+
these channels are normally disabled on a production network to mitigate abuse
102+
from broken or malicious code. However, it is possible to enable this output
103+
even for peer-managed containers (e.g. “netmode”) on a per-peer basis
104+
via the CORE_VM_DOCKER_ATTACHSTDOUT=true configuration option.
110105

111-
Once enabled, each chaincode will receive its own logging channel keyed
112-
by its container-id. Any output written to either stdout or stderr will
113-
be integrated with the peer's log on a per-line basis. It is not
114-
recommended to enable this for production.
106+
Once enabled, each chaincode will receive its own logging channel keyed by its
107+
container-id. Any output written to either stdout or stderr will be integrated
108+
with the peers log on a per-line basis. It is not recommended to enable this
109+
for production.
115110

116-
API
117-
~~~
118-
119-
``NewLogger(name string) *ChaincodeLogger`` - Create a logging object
120-
for use by a chaincode
121-
122-
``(c *ChaincodeLogger) SetLevel(level LoggingLevel)`` - Set the logging
123-
level of the logger
124-
125-
``(c *ChaincodeLogger) IsEnabledFor(level LoggingLevel) bool`` - Return
126-
true if logs will be generated at the given level
127-
128-
``LogLevel(levelString string) (LoggingLevel, error)`` - Convert a
129-
string to a ``LoggingLevel``
130-
131-
A ``LoggingLevel`` is a member of the enumeration
132-
133-
::
134-
135-
LogDebug, LogInfo, LogNotice, LogWarning, LogError, LogCritical
136-
137-
which can be used directly, or generated by passing a case-insensitive
138-
version of the strings
139-
140-
::
141-
142-
DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL
143-
144-
to the ``LogLevel`` API.
145-
146-
Formatted logging at various severity levels is provided by the
147-
functions
148-
149-
::
150-
151-
(c *ChaincodeLogger) Debug(args ...interface{})
152-
(c *ChaincodeLogger) Info(args ...interface{})
153-
(c *ChaincodeLogger) Notice(args ...interface{})
154-
(c *ChaincodeLogger) Warning(args ...interface{})
155-
(c *ChaincodeLogger) Error(args ...interface{})
156-
(c *ChaincodeLogger) Critical(args ...interface{})
157-
158-
(c *ChaincodeLogger) Debugf(format string, args ...interface{})
159-
(c *ChaincodeLogger) Infof(format string, args ...interface{})
160-
(c *ChaincodeLogger) Noticef(format string, args ...interface{})
161-
(c *ChaincodeLogger) Warningf(format string, args ...interface{})
162-
(c *ChaincodeLogger) Errorf(format string, args ...interface{})
163-
(c *ChaincodeLogger) Criticalf(format string, args ...interface{})
164-
165-
The ``f`` forms of the logging APIs provide for precise control over the
166-
formatting of the logs. The non-\ ``f`` forms of the APIs currently
167-
insert a space between the printed representations of the arguments, and
168-
arbitrarily choose the formats to use.
169-
170-
In the current implementation, the logs produced by the ``shim`` and a
171-
``ChaincodeLogger`` are timestamped, marked with the logger *name* and
172-
severity level, and written to ``stderr``. Note that logging level
173-
control is currently based on the *name* provided when the
174-
``ChaincodeLogger`` is created. To avoid ambiguities, all
175-
``ChaincodeLogger`` should be given unique names other than "shim". The
176-
logger *name* will appear in all log messages created by the logger. The
177-
``shim`` logs as "shim".
178-
179-
The default logging level for loggers within the Chaincode container can
180-
be set in the
181-
`core.yaml <https://github.com/hyperledger/fabric/blob/master/sampleconfig/core.yaml>`__
182-
file. The key ``chaincode.logging.level`` sets the default level for all
183-
loggers within the Chaincode container. The key ``chaincode.logging.shim``
184-
overrides the default level for the ``shim`` logger.
185-
186-
::
187-
188-
# Logging section for the chaincode container
189-
logging:
190-
# Default level for all loggers within the chaincode container
191-
level: info
192-
# Override default level for the 'shim' logger
193-
shim: warning
194-
195-
The default logging level can be overridden by using environment
196-
variables. ``CORE_CHAINCODE_LOGGING_LEVEL`` sets the default logging
197-
level for all loggers. ``CORE_CHAINCODE_LOGGING_SHIM`` overrides the
198-
level for the ``shim`` logger.
199-
200-
Go language chaincodes can also control the logging level of the
201-
chaincode ``shim`` interface through the ``SetLoggingLevel`` API.
202-
203-
``SetLoggingLevel(LoggingLevel level)`` - Control the logging level of
204-
the shim
205-
206-
Below is a simple example of how a chaincode might create a private
207-
logging object logging at the ``LogInfo`` level.
111+
Stdout and stderr not forwarded to the peer container can be viewed from the
112+
chaincode container using standard commands for your container platform.
208113

209114
::
210115

211-
var logger = shim.NewLogger("myChaincode")
116+
docker logs <chaincode_container_id>
117+
kubectl logs -n <namespace> <pod_name>
118+
oc logs -n <namespace> <pod_name>
212119

213-
func main() {
214120

215-
logger.SetLevel(shim.LogInfo)
216-
...
217-
}
218121

219122
.. Licensed under Creative Commons Attribution 4.0 International License
220123
https://creativecommons.org/licenses/by/4.0/

0 commit comments

Comments
 (0)