File: logging.rst

package info (click to toggle)
praw 7.7.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 149,360 kB
  • sloc: python: 16,669; makefile: 131
file content (37 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Logging in PRAW
===============

It is occasionally useful to observe the HTTP requests that PRAW is issuing. To do so
you have to configure and enable logging.

Add the following to your code to log everything available:

.. code-block:: python

    import logging

    handler = logging.StreamHandler()
    handler.setLevel(logging.DEBUG)
    for logger_name in ("praw", "prawcore"):
        logger = logging.getLogger(logger_name)
        logger.setLevel(logging.DEBUG)
        logger.addHandler(handler)

When properly configured, HTTP requests that are issued should produce output similar to
the following:

.. code-block:: text

    Fetching: GET https://oauth.reddit.com/api/v1/me
    Data: None
    Params: {'raw_json': 1}
    Response: 200 (876 bytes)

Furthermore, any API ratelimits from POST actions that are handled will produce a log
entry with a message similar to the following message:

.. code-block:: text

    Rate limit hit, sleeping for 5.5 seconds

For more information on logging, see :py:class:`logging.Logger`.