Coverage for o2/util/indented_printer.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-05-16 11:18 +0000

1import logging 

2from textwrap import TextWrapper 

3 

4from o2.util.logger import STATS_LOG_LEVEL, log 

5 

6PREFERRED_WIDTH = 120 

7 

8l1_prefix = 4 * " " + "> " 

9text_wrapper_l1 = TextWrapper( 

10 initial_indent=l1_prefix, 

11 width=PREFERRED_WIDTH, 

12 subsequent_indent=" " * (len(l1_prefix) + 35), 

13) 

14 

15l2_prefix = 6 * " " + ">> " 

16text_wrapper_l2 = TextWrapper( 

17 initial_indent=l2_prefix, 

18 width=PREFERRED_WIDTH, 

19 subsequent_indent=" " * (len(l2_prefix) + 35), 

20) 

21 

22l3_prefix = 8 * " " + ">>> " 

23text_wrapper_l3 = TextWrapper( 

24 initial_indent=l3_prefix, 

25 width=PREFERRED_WIDTH, 

26 subsequent_indent=" " * (len(l3_prefix) + 35), 

27) 

28 

29l4_prefix = 10 * " " + ">>>> " 

30text_wrapper_l4 = TextWrapper( 

31 initial_indent=l4_prefix, 

32 width=PREFERRED_WIDTH, 

33 subsequent_indent=" " * (len(l4_prefix) + 35), 

34) 

35 

36 

37def print_l0(string: str, log_level: int = STATS_LOG_LEVEL) -> None: 

38 """Print a string with no indentation.""" 

39 log(log_level, string) 

40 

41 

42def print_l1(string: str, log_level: int = logging.INFO) -> None: 

43 """Print a string with l1 indentation.""" 

44 log(log_level, text_wrapper_l1.fill(string)) 

45 

46 

47def print_l2(string: str, log_level: int = logging.DEBUG) -> None: 

48 """Print a string with l2 indentation.""" 

49 log(log_level, text_wrapper_l2.fill(string)) 

50 

51 

52def print_l3(string: str, log_level: int = logging.DEBUG) -> None: 

53 """Print a string with l3 indentation.""" 

54 log(log_level, text_wrapper_l3.fill(string)) 

55 

56 

57def print_l4(string: str, log_level: int = logging.DEBUG) -> None: 

58 """Print a string with l4 indentation.""" 

59 log(log_level, text_wrapper_l4.fill(string))