Skip to content

Commit 5519fa7

Browse files
committed
Added logging section to intro doc
1 parent 42c1ddd commit 5519fa7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/introduction.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,34 @@ object, that encapsulates command metadata and the result of the request.
232232

233233
The complete list of available commands and their documentations are
234234
available in their respective API documentation categories.
235+
236+
Logging
237+
-------
238+
239+
For debugging purposes it might be very useful to have a log of certain events,
240+
errors and debug information. To support this, the instrument classes all take
241+
an optional :class:`~logging.Logger` object, that they use to log specific
242+
events. The :func:`~geocompy.communication.get_logger` utility function can be
243+
used to create a simple logger.
244+
245+
.. code-block:: python
246+
:caption: Passing a console logger
247+
:linenos:
248+
249+
from logging import DEBUG
250+
251+
from geocompy.communication import open_serial, get_logger
252+
from geocompy.dna import DNA
253+
254+
255+
log = get_logger("DNA", "stdout", DEBUG)
256+
with open_serial("COM1", timeout=15) as conn:
257+
level = DNA(conn, log)
258+
259+
Some examples of the information logged on various levels:
260+
261+
- connection start
262+
- instrument wake up
263+
- instrument shutdown
264+
- all unexpected exceptions
265+
- all command responses

0 commit comments

Comments
 (0)