_logging.py
1 # SPDX-License-Identifier: MIT 2 # 3 # Copyright (c) 2021 The Anvil Extras project team members listed at 4 # https://github.com/anvilistas/anvil-extras/graphs/contributors 5 # 6 # This software is published at https://github.com/anvilistas/anvil-extras 7 8 __version__ = "3.1.0" 9 10 from ..logging import DEBUG, INFO 11 from ..logging import Logger as _Logger 12 13 14 class Logger(_Logger): 15 def get_format_params(self, *, msg, **params): 16 from . import _router 17 18 indent = " " * len(_router.navigation_context.contexts) 19 msg = msg.replace("\n", "\n" + " " * len(f"{indent}{self.name}: ")) 20 return super().get_format_params(indent=indent, msg=msg, **params) 21 22 def __setattr__(self, attr: str, value) -> None: 23 if attr == "debug": # backwards compatability 24 return _Logger.__setattr__(self, "level", DEBUG if value else INFO) 25 return _Logger.__setattr__(self, attr, value) 26 27 28 logger = Logger("#routing", format="{indent}{name}: {msg}", level=INFO)