Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / auto_parallel / sapp_nd / memory_estimation / logger.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-07-06 05:41 +0800

1# Copyright 2025 Huawei Technologies Co., Ltd 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================ 

15"""logger for parall""" 

16import logging 

17 

18 

19DEFAULT_STDOUT_FORMAT = ( 

20 "[%(levelname)s] %(asctime)s [%(filename)s:%(lineno)d] - %(message)s" 

21) 

22PPB_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 

23PARALL_FORMAT = ( 

24 "%(name)s [%(filename)s:%(lineno)d] - %(levelname)s - %(message)s" 

25) 

26 

27FORMATTER = logging.Formatter(PARALL_FORMAT) 

28OUTPUT_LEVEL_NUM = logging.CRITICAL 

29logging.addLevelName(OUTPUT_LEVEL_NUM, "OUTPUT") 

30 

31 

32def setup_logger(name: str, level: int = logging.DEBUG): 

33 """Set up a logger. 

34 

35 Args: 

36 name (str): Logger name. 

37 level (int, optional): Logging level. Default: logging.DEBUG. 

38 

39 Returns: 

40 logging.Logger: Configured logger. 

41 """ 

42 ch = logging.StreamHandler() 

43 ch.setLevel(level) 

44 ch.setFormatter(FORMATTER) 

45 

46 logging.Logger.output = logging.Logger.critical 

47 memory_logger = logging.getLogger(name) 

48 memory_logger.setLevel(level) 

49 memory_logger.addHandler(ch) 

50 

51 return memory_logger 

52 

53 

54logger = setup_logger("memory_estimation")