Skip to content

Commit

Permalink
Add logging documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Feb 4, 2022
1 parent a702325 commit 7701506
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Contents:
asyncstream.rst
exceptions.rst
extended_tweets.rst
logging.rst
pagination.rst
streaming.rst
changelog.md
Expand Down
35 changes: 35 additions & 0 deletions docs/logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _logging:

*******
Logging
*******

Tweepy uses the :mod:`logging` standard library module.

The simplest way to set up logging is using :func:`logging.basicConfig`, e.g.::

import logging
logging.basicConfig(level=logging.DEBUG)

This will output logging from Tweepy, as well as other libraries (like Tweepy's
dependencies) that use the :mod:`logging` module, directly to the console.

The optional ``level`` argument can be any
:ref:`logging level <python:levels>`.

To configure logging for Tweepy (or each individual library) specifically, you
can use :func:`logging.getLogger` to retrieve the logger for the library. For
example::

import logging
logger = logging.getLogger("Tweepy")
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename="tweepy.log")
logger.addHandler(handler)

More advanced configuration is possible with the :mod:`logging` module.
For more information, see the
:doc:`logging module documentation <python:library/logging>` and
:doc:`tutorials <python:howto/logging>`.

0 comments on commit 7701506

Please sign in to comment.