Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue184 loguru debug #204

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions logger_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""This test is to test that logging works properly when importing torchquad."""

import unittest
from contextlib import contextmanager
from loguru import logger

@contextmanager
def capture_logs(level = "INFO", format="{message}"):
""""Capture loguru-based logs."""
output = []
handler_id = logger.add(output.append, level = level, format = format)

yield output
logger.remove(handler_id)

class TestLogger(unittest.TestCase):

def test_logging_with_tq(self):
import torchquad
with capture_logs() as cap_log:
logger.info("This message should print.")
self.assertEqual(cap_log,["This message should print.\n"])

3 changes: 2 additions & 1 deletion torchquad/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from loguru import logger
#Called to prevent library logs from being mixed with thoes of the user.
logger.disable("torchquad")

# TODO: Currently this is the way to expose to the docs
# hopefully changes with setup.py
Expand Down Expand Up @@ -46,5 +48,4 @@
"_deployment_test",
]

set_log_level(os.environ.get("TORCHQUAD_LOG_LEVEL", "WARNING"))
logger.info("Initializing torchquad.")
Loading