Skip to content

Commit

Permalink
iter: bind internal context for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
blepabyte committed Oct 6, 2024
1 parent 90ae0ee commit 8cc4c96
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
21 changes: 3 additions & 18 deletions maxray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,12 @@

import os

from loguru import logger
from loguru import logger as _logger
from .logging import logger

if not os.environ.get("MAXRAY_LOG_LEVEL"):
# Avoid logspam for users of the library
logger.disable("maxray")


def _set_logging(enabled: bool):
if enabled:
logger.enable("maxray")
else:
logger.disable("maxray")


@contextmanager
def _with_logging():
try:
_set_logging(True)
yield
finally:
_set_logging(False)
_logger.disable("maxray")


def transform(writer):
Expand Down
2 changes: 1 addition & 1 deletion maxray/function_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pathlib import Path
from typing import Any, Optional

from loguru import logger
from .logging import logger


method_wrapper = type(object().__init__)
Expand Down
3 changes: 3 additions & 0 deletions maxray/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from loguru import logger as _logger

logger = _logger.bind(maxray_internal=True)
3 changes: 1 addition & 2 deletions maxray/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import Any, Callable, Optional

from loguru import logger
from .logging import logger


@dataclass
Expand All @@ -21,7 +21,6 @@ class FnContext:
line_offset: int
"Line number in `source_file` at which the function definition begins."

call_count: ContextVar[int]
compile_id: str

def __repr__(self):
Expand Down

0 comments on commit 8cc4c96

Please sign in to comment.