summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2022-11-01 23:00:17 (GMT)
committerGitHub <noreply@github.com>2022-11-01 23:00:17 (GMT)
commit50a9b037a6603e73f0a850f5d43dbdd2656e60b1 (patch)
tree560f68ef0ce0b0aae0437812c306a84c39f76b90 /Doc/howto
parent9711265182f163ba381e7800e3748ac28710f9ef (diff)
downloadcpython-50a9b037a6603e73f0a850f5d43dbdd2656e60b1.zip
cpython-50a9b037a6603e73f0a850f5d43dbdd2656e60b1.tar.gz
cpython-50a9b037a6603e73f0a850f5d43dbdd2656e60b1.tar.bz2
[doc] Update cookbook example for socket-based logging in a production sett… (GH-98922)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/logging-cookbook.rst72
1 files changed, 65 insertions, 7 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst
index ae101e3..bf6f54a 100644
--- a/Doc/howto/logging-cookbook.rst
+++ b/Doc/howto/logging-cookbook.rst
@@ -765,13 +765,71 @@ serialization.
Running a logging socket listener in production
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-To run a logging listener in production, you may need to use a process-management tool
-such as `Supervisor <http://supervisord.org/>`_. `Here
-<https://gist.github.com/vsajip/4b227eeec43817465ca835ca66f75e2b>`_ is a Gist which
-provides the bare-bones files to run the above functionality using Supervisor: you
-will need to change the ``/path/to/`` parts in the Gist to reflect the actual paths you
-want to use.
-
+.. _socket-listener-gist: https://gist.github.com/vsajip/4b227eeec43817465ca835ca66f75e2b
+
+To run a logging listener in production, you may need to use a
+process-management tool such as `Supervisor <http://supervisord.org/>`_.
+`Here is a Gist <socket-listener-gist_>`__
+which provides the bare-bones files to run the above functionality using
+Supervisor. It consists of the following files:
+
++-------------------------+----------------------------------------------------+
+| File | Purpose |
++=========================+====================================================+
+| :file:`prepare.sh` | A Bash script to prepare the environment for |
+| | testing |
++-------------------------+----------------------------------------------------+
+| :file:`supervisor.conf` | The Supervisor configuration file, which has |
+| | entries for the listener and a multi-process web |
+| | application |
++-------------------------+----------------------------------------------------+
+| :file:`ensure_app.sh` | A Bash script to ensure that Supervisor is running |
+| | with the above configuration |
++-------------------------+----------------------------------------------------+
+| :file:`log_listener.py` | The socket listener program which receives log |
+| | events and records them to a file |
++-------------------------+----------------------------------------------------+
+| :file:`main.py` | A simple web application which performs logging |
+| | via a socket connected to the listener |
++-------------------------+----------------------------------------------------+
+| :file:`webapp.json` | A JSON configuration file for the web application |
++-------------------------+----------------------------------------------------+
+| :file:`client.py` | A Python script to exercise the web application |
++-------------------------+----------------------------------------------------+
+
+The web application uses `Gunicorn <https://gunicorn.org/>`_, which is a
+popular web application server that starts multiple worker processes to handle
+requests. This example setup shows how the workers can write to the same log file
+without conflicting with one another --- they all go through the socket listener.
+
+To test these files, do the following in a POSIX environment:
+
+#. Download `the Gist <socket-listener-gist_>`__
+ as a ZIP archive using the :guilabel:`Download ZIP` button.
+
+#. Unzip the above files from the archive into a scratch directory.
+
+#. In the scratch directory, run ``bash prepare.sh`` to get things ready.
+ This creates a :file:`run` subdirectory to contain Supervisor-related and
+ log files, and a :file:`venv` subdirectory to contain a virtual environment
+ into which ``bottle``, ``gunicorn`` and ``supervisor`` are installed.
+
+#. Run ``bash ensure_app.sh`` to ensure that Supervisor is running with
+ the above configuration.
+
+#. Run ``venv/bin/python client.py`` to exercise the web application,
+ which will lead to records being written to the log.
+
+#. Inspect the log files in the :file:`run` subdirectory. You should see the
+ most recent log lines in files matching the pattern :file:`app.log*`. They won't be in
+ any particular order, since they have been handled concurrently by different
+ worker processes in a non-deterministic way.
+
+#. You can shut down the listener and the web application by running
+ ``venv/bin/supervisorctl -c supervisor.conf shutdown``.
+
+You may need to tweak the configuration files in the unlikely event that the
+configured ports clash with something else in your test environment.
.. _context-info: