Coverage for /home/runner/work/viur-core/viur-core/viur/src/viur/core/render/html/env/debug.py: 0%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-16 22:16 +0000

1from logging import critical, debug, error, info, warning 

2 

3import pprint 

4import typing as t 

5 

6from ..utils import jinjaGlobalFunction 

7from ..default import Render 

8 

9 

10@jinjaGlobalFunction 

11def logging(render: Render, msg: str, level: str = "info", *args, **kwargs) -> None: 

12 """ 

13 Jinja2 global: Write log-level entry. 

14 

15 The function shall be used for debug and tracing purposes. 

16 

17 :param render: The html-renderer instance. 

18 :param msg: Message to be delivered into logging. 

19 :param level: Logging level. This can either be "info" (default), "debug", "warning", "error" or "critical". 

20 """ 

21 

22 level = level.lower() 

23 

24 if level == "critical": 

25 critical(msg, *args, **kwargs) 

26 elif level == "error": 

27 error(msg, *args, **kwargs) 

28 elif level == "warning": 

29 warning(msg, *args, **kwargs) 

30 elif level == "debug": 

31 debug(msg, *args, **kwargs) 

32 else: 

33 info(msg, *args, **kwargs) 

34 

35 

36@jinjaGlobalFunction 

37def pprint(render: Render, obj: t.Any) -> str: 

38 """ 

39 Jinja2 global: Provides a pprint function that renders into HTML. 

40 The function shall be used for debug purposes. 

41 

42 :param render: The html-renderer instance. 

43 :param obj: Object to be pprinted. 

44 :return: HTML-enabled pprint output. 

45 """ 

46 return pprint.pformat(obj).replace("\n", "<br>").replace(" ", "&nbsp;")