Skip to content

Commit 7bfb114

Browse files
committed
Add standalone guide to enable debug logs.
Pointing to this information is frequently needed in the issue tracker.
1 parent 74a7ac2 commit 7bfb114

File tree

5 files changed

+55
-51
lines changed

5 files changed

+55
-51
lines changed

docs/faq/common.rst

+2-30
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,6 @@ Both sides
33

44
.. currentmodule:: websockets.asyncio.connection
55

6-
.. _enable-debug-logs:
7-
8-
How do I enable debug logs?
9-
---------------------------
10-
11-
You can enable debug logs to see exactly what websockets is doing.
12-
13-
If logging isn't configured in your application::
14-
15-
import logging
16-
17-
logging.basicConfig(
18-
format="%(asctime)s %(message)s",
19-
level=logging.DEBUG,
20-
)
21-
22-
If logging is already configured::
23-
24-
import logging
25-
26-
logger = logging.getLogger("websockets")
27-
logger.setLevel(logging.DEBUG)
28-
logger.addHandler(logging.StreamHandler())
29-
30-
Refer to the :doc:`logging documentation <../topics/logging>` for more details
31-
on logging in websockets.
32-
336
What does ``ConnectionClosedError: no close frame received or sent`` mean?
347
--------------------------------------------------------------------------
358

@@ -66,9 +39,8 @@ There are several reasons why long-lived connections may be lost:
6639
connections may terminate connections after a short amount of time, usually
6740
30 seconds, despite websockets' keepalive mechanism.
6841

69-
If you're facing a reproducible issue, :ref:`enable debug logs
70-
<enable-debug-logs>` to see when and how connections are closed. connections are
71-
closed.
42+
If you're facing a reproducible issue, :doc:`enable debug logs
43+
<../howto/debugging>` to see when and how connections are closed.
7244

7345
What does ``ConnectionClosedError: sent 1011 (internal error) keepalive ping timeout; no close frame received`` mean?
7446
---------------------------------------------------------------------------------------------------------------------

docs/howto/autoreload.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ stop the server and restart it, which slows down your development process.
77

88
Web frameworks such as Django or Flask provide a development server that
99
reloads the application automatically when you make code changes. There is no
10-
such functionality in websockets because it's designed for production rather
11-
than development.
10+
such functionality in websockets because it's designed only for production.
1211

1312
However, you can achieve the same result easily.
1413

@@ -27,5 +26,5 @@ Run your server with ``watchmedo auto-restart``:
2726
$ watchmedo auto-restart --pattern "*.py" --recursive --signal SIGTERM \
2827
python app.py
2928
30-
This example assumes that the server is defined in a script called ``app.py``.
31-
Adapt it as necessary.
29+
This example assumes that the server is defined in a script called ``app.py``
30+
and exits cleanly when receiving the ``SIGTERM`` signal. Adapt it as necessary.

docs/howto/debugging.rst

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Enable debug logs
2+
==================
3+
4+
websockets logs events with the :mod:`logging` module from the standard library.
5+
6+
It writes to the ``"websockets.server"`` and ``"websockets.client"`` loggers.
7+
8+
Enable logs at the ``DEBUG`` level to see exactly what websockets is doing.
9+
10+
If logging isn't configured in your application::
11+
12+
import logging
13+
14+
logging.basicConfig(
15+
format="%(asctime)s %(message)s",
16+
level=logging.DEBUG,
17+
)
18+
19+
If logging is already configured::
20+
21+
import logging
22+
23+
logger = logging.getLogger("websockets")
24+
logger.setLevel(logging.DEBUG)
25+
logger.addHandler(logging.StreamHandler())
26+
27+
Refer to the :doc:`logging guide <../topics/logging>` for more details on
28+
logging in websockets.
29+
30+
In addition, you may enable asyncio's `debug mode`_ to see what asyncio is
31+
doing.
32+
33+
.. _debug mode: https://docs.python.org/3/library/asyncio-dev.html#asyncio-debug-mode

docs/howto/index.rst

+13-16
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,30 @@ How-to guides
44
In a hurry? Check out these examples.
55

66
.. toctree::
7-
:titlesonly:
87

98
quickstart
10-
11-
Upgrading from the legacy :mod:`asyncio` implementation to the new one?
12-
Read this.
13-
14-
.. toctree::
15-
:titlesonly:
16-
17-
upgrade
9+
debugging
10+
autoreload
1811

1912
If you're stuck, perhaps you'll find the answer here.
2013

2114
.. toctree::
22-
:titlesonly:
2315

2416
patterns
25-
autoreload
2617

2718
This guide will help you integrate websockets into a broader system.
2819

2920
.. toctree::
30-
:titlesonly:
3121

3222
django
3323

34-
The WebSocket protocol makes provisions for extending or specializing its
35-
features, which websockets supports fully.
24+
Upgrading from the legacy :mod:`asyncio` implementation to the new one?
25+
Read this.
3626

3727
.. toctree::
38-
:titlesonly:
28+
:maxdepth: 2
3929

40-
extensions
30+
upgrade
4131

4232
If you're integrating the Sans-I/O layer of websockets into a library, rather
4333
than building an application with websockets, follow this guide.
@@ -46,3 +36,10 @@ than building an application with websockets, follow this guide.
4636
:maxdepth: 2
4737

4838
sansio
39+
40+
The WebSocket protocol makes provisions for extending or specializing its
41+
features, which websockets supports fully.
42+
43+
.. toctree::
44+
45+
extensions

docs/intro/tutorial1.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,10 @@ taking alternate turns.
545545
546546
import logging
547547
548-
logging.basicConfig(format="%(message)s", level=logging.DEBUG)
548+
logging.basicConfig(
549+
format="%(asctime)s %(message)s",
550+
level=logging.DEBUG,
551+
)
549552
550553
If you're stuck, a solution is available at the bottom of this document.
551554

0 commit comments

Comments
 (0)