Skip to content

Commit

Permalink
don't use the root logger to allow disabling joppy log in other apps
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Apr 9, 2024
1 parent 1822b48 commit 410ab46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ It's possible to configure the test run via some environment variables:

## :book: Changelog

### Master

- Don't use the root logger for logging.

### 0.2.2

- Fix adding non-image ressources (<https://github.com/marph91/joppy/issues/24>).
Expand Down
10 changes: 5 additions & 5 deletions joppy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

LOGGER = logging.getLogger("joppy")


##############################################################################
# Base wrapper that manages the requests to the REST API.
Expand All @@ -50,7 +52,7 @@ def _request(
data: Optional[dt.JoplinKwargs] = None,
files: Optional[Dict[str, Any]] = None,
) -> requests.models.Response:
logging.debug(
LOGGER.debug(
f"API: {method} request: path={path}, query={query}, data={data}, "
f"files={files}"
)
Expand All @@ -68,7 +70,7 @@ def _request(
json=data,
files=files,
)
logging.debug(f"API: response {response.text}")
LOGGER.debug(f"API: response {response.text}")
response.raise_for_status()
except requests.exceptions.HTTPError as err:
err.args = err.args + (response.text,)
Expand Down Expand Up @@ -294,9 +296,7 @@ def modify_revision(self, id_: str, **data: dt.JoplinTypes) -> None:


class Search(ApiBase):
def search(
self, **query: dt.JoplinTypes
) -> Union[
def search(self, **query: dt.JoplinTypes) -> Union[
dt.DataList[dt.NoteData],
dt.DataList[dt.NotebookData],
dt.DataList[dt.ResourceData],
Expand Down
5 changes: 3 additions & 2 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
format="%(asctime)s [%(levelname)s]: %(message)s",
level=logging.DEBUG,
)
LOGGER = logging.getLogger("joppy")


SLOW_TESTS = bool(os.getenv("SLOW_TESTS", ""))
Expand Down Expand Up @@ -70,7 +71,7 @@ class TestBase(unittest.TestCase):
def setUp(self):
super().setUp()

logging.debug("Test: %s", self.id())
LOGGER.debug("Test: %s", self.id())

self.api = Api(token=API_TOKEN)
# Notes get deleted automatically.
Expand All @@ -93,7 +94,7 @@ def get_random_string(length: int = 8, exclude: str = "") -> str:
for character in exclude:
characters = characters.replace(character, "")
random_string = "".join(random.choice(characters) for _ in range(length))
logging.debug("Test: random string: %s", random_string)
LOGGER.debug("Test: random string: %s", random_string)
return random_string

@staticmethod
Expand Down

0 comments on commit 410ab46

Please sign in to comment.