Anthony DiGirolamo | 4644099 | 2021-07-19 16:07:47 -0700 | [diff] [blame] | 1 | .. _module-pw_console-embedding: |
| 2 | |
| 3 | Embedding Guide |
| 4 | =============== |
| 5 | |
| 6 | Using embed() |
| 7 | ------------- |
| 8 | |
Anthony DiGirolamo | bf5682a | 2021-08-02 13:51:34 -0700 | [diff] [blame] | 9 | ``pw console`` is invoked by calling ``PwConsoleEmbed().embed()`` in your |
| 10 | own Python script. |
Anthony DiGirolamo | 4644099 | 2021-07-19 16:07:47 -0700 | [diff] [blame] | 11 | |
Anthony DiGirolamo | bf5682a | 2021-08-02 13:51:34 -0700 | [diff] [blame] | 12 | .. automodule:: pw_console.embed |
| 13 | :members: PwConsoleEmbed |
Anthony DiGirolamo | 4644099 | 2021-07-19 16:07:47 -0700 | [diff] [blame] | 14 | :undoc-members: |
| 15 | :show-inheritance: |
| 16 | |
| 17 | Adding Log Metadata |
| 18 | ------------------- |
| 19 | |
| 20 | ``pw_console`` can display log messages in a table with justified columns for |
| 21 | metadata fields provided by :ref:`module-pw_log_tokenized`. |
| 22 | |
| 23 | It is also possible to manually add values that should be displayed in columns |
| 24 | using the ``extra`` keyword argument when logging from Python. See the `Python's |
| 25 | logging documentation`_ for how ``extra`` works. A dict of name, value pairs can |
| 26 | be passed in as the ``extra_metadata_fields`` variable. For example, the |
| 27 | following 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 |