blob: bdcbc5c5f6d06788da2605286448b8558b106cd4 [file] [log] [blame]
Anthony DiGirolamo46440992021-07-19 16:07:47 -07001.. _module-pw_console-embedding:
2
3Embedding Guide
4===============
5
6Using embed()
7-------------
8
Anthony DiGirolamobf5682a2021-08-02 13:51:34 -07009``pw console`` is invoked by calling ``PwConsoleEmbed().embed()`` in your
10own Python script.
Anthony DiGirolamo46440992021-07-19 16:07:47 -070011
Anthony DiGirolamobf5682a2021-08-02 13:51:34 -070012.. automodule:: pw_console.embed
13 :members: PwConsoleEmbed
Anthony DiGirolamo46440992021-07-19 16:07:47 -070014 :undoc-members:
15 :show-inheritance:
16
17Adding Log Metadata
18-------------------
19
20``pw_console`` can display log messages in a table with justified columns for
21metadata fields provided by :ref:`module-pw_log_tokenized`.
22
23It is also possible to manually add values that should be displayed in columns
24using the ``extra`` keyword argument when logging from Python. See the `Python's
25logging documentation`_ for how ``extra`` works. A dict of name, value pairs can
26be passed in as the ``extra_metadata_fields`` variable. For example, the
27following code will create a log message with two custom columns titled
28``module`` and ``timestamp``.
29
30.. code-block:: python
31
32 import logging
33
34 LOG = logging.getLogger('log_source_1')
35
36 LOG.info(
37 'Hello there!',
38 extra={
39 'extra_metadata_fields': {
40 'module': 'cool',
41 'timestamp': 1.2345,
42 }
43 }
44 )
45
46.. _Python's logging documentation: https://docs.python.org/3/library/logging.html#logging.Logger.debug