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

19 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-08-21 04:29 +0800

1# Copyright 2026 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 pipeline balance""" 

16import logging 

17 

18DEFAULT_STDOUT_FORMAT = '%(levelname)s %(asctime)s %(filename)s:%(lineno)d - %(message)s' 

19FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 

20_HANDLER_NAME = 'sapp_ppb_stream_handler' 

21 

22 

23def setup_logger(name: str, level: int = logging.DEBUG) -> logging.Logger: 

24 """Create a namespaced logger and register the ``output`` convenience level. 

25 

26 Args: 

27 name: Logger name (typically a package or module name). 

28 level: Minimum log level accepted by both the logger and the handler. 

29 

30 Returns: 

31 The configured :class:`logging.Logger` instance. 

32 """ 

33 def output(self: logging.Logger, message: str, *args: object) -> None: 

34 """Emit ``message`` at the warning level.""" 

35 self.warning(message, *args) 

36 

37 logging.Logger.output = output 

38 ppb_logger = logging.getLogger(name) 

39 ppb_logger.setLevel(level) 

40 handler = next( 

41 (item for item in ppb_logger.handlers if item.get_name() == _HANDLER_NAME), 

42 None, 

43 ) 

44 if handler is None: 

45 handler = logging.StreamHandler() 

46 handler.set_name(_HANDLER_NAME) 

47 ppb_logger.addHandler(handler) 

48 handler.setLevel(level) 

49 handler.setFormatter(FORMATTER) 

50 

51 return ppb_logger 

52 

53logger = setup_logger('sapp_ppb', level=logging.INFO)