Change logging

We now use our own logger.
When debug is set (-vvv), we also display urllib3's debug info.
This commit is contained in:
benoit 2023-03-14 17:50:31 +01:00 committed by Benoit
parent 7256c1894a
commit 2443505ad6
4 changed files with 9 additions and 6 deletions

View file

@ -33,7 +33,7 @@ from .node import (
from .types import ConnectionInfo, Parameters
from .convert import size_to_byte
_log = logging.getLogger("nagiosplugin")
_log = logging.getLogger(__name__)
DEFAULT_CFG = "config.ini"
@ -162,6 +162,10 @@ def main(
tendpoints += re.split(r"\s*,\s*", e)
endpoints = tendpoints
if verbose == 3:
logging.basicConfig(format="%(levelname)s - %(message)s", level=logging.DEBUG)
logging.getLogger("urllib3").setLevel(logging.DEBUG)
ctx.obj = Parameters(
ConnectionInfo(endpoints, cert_file, key_file, ca_file),
timeout,

View file

@ -8,7 +8,7 @@ from typing import Iterable, Union
from .types import PatroniResource, ConnectionInfo, handle_unknown
_log = logging.getLogger("nagiosplugin")
_log = logging.getLogger(__name__)
def replace_chars(text: str) -> str:

View file

@ -5,7 +5,7 @@ from typing import Iterable
from .types import APIError, ConnectionInfo, handle_unknown, PatroniResource
_log = logging.getLogger("nagiosplugin")
_log = logging.getLogger(__name__)
class NodeIsPrimary(PatroniResource):

View file

@ -3,10 +3,9 @@ import logging
import attr
import nagiosplugin
import requests
import urllib3
from typing import Any, Callable, List, Optional, Tuple, Union
_log = logging.getLogger("nagiosplugin")
_log = logging.getLogger(__name__)
class APIError(requests.exceptions.RequestException):
@ -71,7 +70,7 @@ class PatroniResource(nagiosplugin.Resource):
)
r = requests.get(f"{endpoint}/{service}", verify=verify, cert=cert)
_log.debug(f"api call status: {r.status_code}")
# The status code is already handled by urllib3
_log.debug(f"api call data: {r.text}")
if r.status_code != 200: