Skip to content

Commit f4eeed8

Browse files
committed
Add function to print warning exactly once
1 parent 2091f9d commit f4eeed8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/graphnet/utilities/logging.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Consistent and configurable logging across the project."""
22

33
from collections import Counter
4+
from functools import lru_cache
45
import re
56
from typing import Optional
67
import colorlog
@@ -53,6 +54,12 @@ def get_formatters() -> Tuple[logging.Formatter, colorlog.ColoredFormatter]:
5354
return basic_formatter, colored_formatter
5455

5556

57+
@lru_cache(1)
58+
def warn_once(logger: logging.Logger, message: str):
59+
"""Print `message` as warning exactly once."""
60+
logger.warn(message)
61+
62+
5663
class RepeatFilter(object):
5764
"""Filter out repeat messages."""
5865

0 commit comments

Comments
 (0)