Skip to content

Commit

Permalink
Update docs with note about logging config (#903)
Browse files Browse the repository at this point in the history
* Update docs with note about logging config
* Switch to __name__ in getLogger()
  • Loading branch information
scaramallion committed Jan 2, 2024
1 parent 8db4ff1 commit a952c71
Show file tree
Hide file tree
Showing 32 changed files with 40 additions and 34 deletions.
10 changes: 8 additions & 2 deletions docs/tutorials/create_scu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ Troubleshooting associations
----------------------------

By itself our output isn't very helpful in understanding what's going on.
Fortunately, by default *pynetdicom* has lots of logging output, which can be
sent to the terminal by calling :func:`~debug_logger`:
Fortunately *pynetdicom* has lots of logging output, but by default its
configured to send it all to the :class:`~logging.NullHandler` which prevents
warnings and errors being printed to ``sys.stderr``. This can be undone by
importing :mod:`logging` and setting ``logging.getLogger("pynetdicom").handlers = []``
or by adding your own logging handlers.

If you need to troubleshoot, then a quick way to send the debugging output to
``sys.stderr`` is by calling :func:`~debug_logger`:

.. code-block:: python
:linenos:
Expand Down
4 changes: 2 additions & 2 deletions pynetdicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@


# Setup default logging
logging.getLogger("pynetdicom").addHandler(logging.NullHandler())
logging.getLogger(__name__).addHandler(logging.NullHandler())


def debug_logger() -> None:
"""Setup the logging for debugging."""
logger = logging.getLogger("pynetdicom")
logger = logging.getLogger(__name__)
# Ensure only have one StreamHandler
logger.handlers = []
handler = logging.StreamHandler()
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from pynetdicom.pdu_items import SOPClassCommonExtendedNegotiation


LOGGER = logging.getLogger("pynetdicom.events")
LOGGER = logging.getLogger(__name__)


# Debugging handlers
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydicom.uid import UID


LOGGER = logging.getLogger("pynetdicom._validators")
LOGGER = logging.getLogger(__name__)


def validate_ae(value: str) -> Tuple[bool, str]:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/acse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pynetdicom.transport import AssociationSocket


LOGGER = logging.getLogger("pynetdicom.acse")
LOGGER = logging.getLogger(__name__)


class ACSE:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)


LOGGER = logging.getLogger("pynetdicom.ae")
LOGGER = logging.getLogger(__name__)


_T = TypeVar("_T")
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@


# pylint: enable=no-name-in-module
LOGGER = logging.getLogger("pynetdicom.assoc")
LOGGER = logging.getLogger(__name__)
HandlerType = dict[
evt.EventType,
(list[tuple[Callable, None | list[Any]]] | tuple[Callable, None | list[Any]]),
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/dimse.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from pynetdicom.pdu_primitives import P_DATA


LOGGER = logging.getLogger("pynetdicom.dimse")
LOGGER = logging.getLogger(__name__)

_RQ_TO_MESSAGE = {
C_ECHO: C_ECHO_RQ,
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/dimse_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from pynetdicom.dimse_primitives import NTF


LOGGER = logging.getLogger("pynetdicom.dimse")
LOGGER = logging.getLogger(__name__)


# PS3.7 Section 9.3
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/dimse_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def close(self) -> None:
...


LOGGER = logging.getLogger("pynetdicom.dimse_primitives")
LOGGER = logging.getLogger(__name__)


DimseServiceType = Union[
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/dsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pynetdicom.utils import pretty_bytes


LOGGER = logging.getLogger("pynetdicom.dsutils")
LOGGER = logging.getLogger(__name__)


def create_file_meta(
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/dul.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
_QueueType = queue.Queue[Union[_PDUPrimitiveType, T_CONNECT]]


LOGGER = logging.getLogger("pynetdicom.dul")
LOGGER = logging.getLogger(__name__)


class DULServiceProvider(Thread):
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
)


LOGGER = logging.getLogger("pynetdicom.events")
LOGGER = logging.getLogger(__name__)


EventType = Union["NotificationEvent", "InterventionEvent"]
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pynetdicom.pdu_primitives import A_ASSOCIATE, P_DATA, A_RELEASE


LOGGER = logging.getLogger("pynetdicom.sm")
LOGGER = logging.getLogger(__name__)


class InvalidEventError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
)


LOGGER = logging.getLogger("pynetdicom.pdu")
LOGGER = logging.getLogger(__name__)

_PDVItem = List[PresentationDataValueItem]
_AbortType = Union["A_ABORT", "A_P_ABORT"]
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/pdu_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
)


LOGGER = logging.getLogger("pynetdicom.pdu_items")
LOGGER = logging.getLogger(__name__)

# Predefine some structs to make decoding and encoding faster
UCHAR = Struct("B")
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/pdu_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pynetdicom.utils import validate_uid, decode_bytes, set_ae, set_uid
from pynetdicom._globals import DEFAULT_MAX_LENGTH

LOGGER = logging.getLogger("pynetdicom.pdu_primitives")
LOGGER = logging.getLogger(__name__)

_PDUPrimitiveType = Union["A_ASSOCIATE", "A_RELEASE", "A_ABORT", "A_P_ABORT", "P_DATA"]
_UserInformationPrimitiveType = List[
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from pynetdicom.pdu_primitives import SCP_SCU_RoleSelectionNegotiation


LOGGER = logging.getLogger("pynetdicom.presentation")
LOGGER = logging.getLogger(__name__)


# Used with the event handlers to give the users access to the context
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/service_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
DestinationType = tuple[str, int] | tuple[str, int, dict[str, Any]]


LOGGER = logging.getLogger("pynetdicom.service-c")
LOGGER = logging.getLogger(__name__)


class attempt:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/service_class_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
_UPS = N_CREATE | N_EVENT_REPORT | N_GET | N_SET | N_ACTION | C_FIND


LOGGER = logging.getLogger("pynetdicom.service-n")
LOGGER = logging.getLogger(__name__)


class ApplicationEventLoggingServiceClass(ServiceClass):
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/sop_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)


LOGGER = logging.getLogger("pynetdicom.sop")
LOGGER = logging.getLogger(__name__)


def uid_to_service_class(uid: str) -> Type[ServiceClass]:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/parrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pynetdicom.transport import AssociationServer


LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)


class ParrotRequest(BaseRequestHandler):
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_dimse_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
)


LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_dimse_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
n_set_rq_cmd_empty,
)

LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_dimse_n.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
PYD_CONFIG.settings.reading_validation_mode = 0


LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from pynetdicom.sop_class import Verification
from pynetdicom.utils import pretty_bytes

LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
PYD_CONFIG.settings.reading_validation_mode = 0


LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
HAS_STATUS = False


LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pynetdicom.timer import Timer
from .utils import sleep

LOGGER = logging.getLogger("pynetdicom")
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.CRITICAL)


Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional


LOGGER = logging.getLogger("pynetdicom.artim")
LOGGER = logging.getLogger(__name__)


class Timer:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from pynetdicom.dul import _QueueType


LOGGER = logging.getLogger("pynetdicom.transport")
LOGGER = logging.getLogger(__name__)


class T_CONNECT:
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pynetdicom import _config


LOGGER = logging.getLogger("pynetdicom.utils")
LOGGER = logging.getLogger(__name__)


def decode_bytes(encoded_value: bytes) -> str:
Expand Down

0 comments on commit a952c71

Please sign in to comment.