Coverage for common/logfunc.py: 56%

9 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2026-02-05 06:46 -0600

1r""" 

2crate_anon/common/logfunc.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CRATE. 

10 

11 CRATE is free software: you can redistribute it and/or modify 

12 it under the terms of the GNU General Public License as published by 

13 the Free Software Foundation, either version 3 of the License, or 

14 (at your option) any later version. 

15 

16 CRATE is distributed in the hope that it will be useful, 

17 but WITHOUT ANY WARRANTY; without even the implied warranty of 

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19 GNU General Public License for more details. 

20 

21 You should have received a copy of the GNU General Public License 

22 along with CRATE. If not, see <https://www.gnu.org/licenses/>. 

23 

24=============================================================================== 

25 

26**Log functions.** 

27 

28""" 

29 

30# ============================================================================= 

31# Imports 

32# ============================================================================= 

33 

34import logging 

35from typing import Set 

36 

37log = logging.getLogger(__name__) 

38 

39 

40# ============================================================================= 

41# Output 

42# ============================================================================= 

43 

44_warned = set() # type: Set[str] 

45 

46 

47def warn_once( 

48 msg: str, logger: logging.Logger = None, level: int = logging.WARN 

49) -> None: 

50 """ 

51 Warns the user once only. 

52 """ 

53 global _warned 

54 logger = logger or log 

55 if msg not in _warned: 

56 logger.log(level, msg) 

57 _warned.add(msg)