From f748de3b296211ee5c640a852b97f4e71ea2cc7c Mon Sep 17 00:00:00 2001 From: Andy Newton Date: Mon, 5 Mar 2018 08:50:45 +0000 Subject: [PATCH] Make log level configurable from environment variables (#622) * `PATRONI_LOGLEVEL` - sets the general logging level * `PATRONI_REQUESTS_LOGLEVEL` - sets the logging level for all HTTP requests e.g. Kubernetes API calls --- docs/ENVIRONMENT.rst | 2 ++ patroni/__init__.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/ENVIRONMENT.rst b/docs/ENVIRONMENT.rst index 7f78db30..6df2ae38 100644 --- a/docs/ENVIRONMENT.rst +++ b/docs/ENVIRONMENT.rst @@ -11,6 +11,8 @@ Global/Universal - **PATRONI\_NAME**: name of the node where the current instance of Patroni is running. Must be unique for the cluster. - **PATRONI\_NAMESPACE**: path within the configuration store where Patroni will keep information about the cluster. Default value: "/service" - **PATRONI\_SCOPE**: cluster name +- **PATRONI\_LOGLEVEL**: sets the general logging level (see `the docs for Python logging `_) +- **PATRONI\_REQUESTS_LOGLEVEL**: sets the logging level for all HTTP requests e.g. Kubernetes API calls (see `the docs for Python logging `_) Bootstrap configuration ----------------------- diff --git a/patroni/__init__.py b/patroni/__init__.py index 6bc56396..40801f65 100644 --- a/patroni/__init__.py +++ b/patroni/__init__.py @@ -135,8 +135,10 @@ class Patroni(object): def patroni_main(): logformat = os.environ.get('PATRONI_LOGFORMAT', '%(asctime)s %(levelname)s: %(message)s') - logging.basicConfig(format=logformat, level=logging.INFO) - logging.getLogger('requests').setLevel(logging.WARNING) + loglevel = os.environ.get('PATRONI_LOGLEVEL', 'INFO') + requests_loglevel = os.environ.get('PATRONI_REQUESTS_LOGLEVEL', 'WARNING') + logging.basicConfig(format=logformat, level=loglevel) + logging.getLogger('requests').setLevel(requests_loglevel) patroni = Patroni() try: