https://github.com/cjrh/arglog
Add root logger config to argparse automatically
https://github.com/cjrh/arglog
argument-parser logging
Last synced: over 1 year ago
JSON representation
Add root logger config to argparse automatically
- Host: GitHub
- URL: https://github.com/cjrh/arglog
- Owner: cjrh
- License: apache-2.0
- Created: 2017-06-30T11:27:15.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-23T13:29:39.000Z (almost 6 years ago)
- Last Synced: 2025-02-27T09:28:05.253Z (over 1 year ago)
- Topics: argument-parser, logging
- Language: Python
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
.. image:: https://img.shields.io/badge/stdlib--only-yes-green.svg
:target: https://img.shields.io/badge/stdlib--only-yes-green.svg
.. image:: https://travis-ci.org/cjrh/arglog.svg?branch=master
:target: https://travis-ci.org/cjrh/arglog
.. image:: https://coveralls.io/repos/github/cjrh/arglog/badge.svg?branch=master
:target: https://coveralls.io/github/cjrh/arglog?branch=master
.. image:: https://img.shields.io/pypi/pyversions/arglog.svg
:target: https://pypi.python.org/pypi/arglog
.. image:: https://img.shields.io/github/tag/cjrh/arglog.svg
:target: https://img.shields.io/github/tag/cjrh/arglog.svg
.. image:: https://img.shields.io/badge/install-pip%20install%20arglog-ff69b4.svg
:target: https://img.shields.io/badge/install-pip%20install%20arglog-ff69b4.svg
arglog
======
*Add logging options to argparse automatically*
Demo
----
.. code:: python
# main.py
import argparse
import logging
import arglog
if __name__ == '__main__':
parser = argparse.ArgumentParser()
arglog.patch(parser)
args = parser.parse_args()
This will trigger the same effect as running:
.. code:: python
logging.basicConfig(level='')
However, you now also have a new CLI option for your program:
.. code:: bash
$ python main.py --loglevel=WARNING
All of the logging levels are supported, ``INFO``, ``DEBUG`` and so on.