initial work on log once option

This commit is contained in:
Daniel A. Wozniak 2024-08-18 15:18:32 -07:00 committed by Daniel Wozniak
parent f9c9787251
commit 468b26e918
2 changed files with 11 additions and 0 deletions

View file

@ -157,6 +157,9 @@ LOGGING_LOGGER_CLASS = logging.getLoggerClass()
class SaltLoggingClass(LOGGING_LOGGER_CLASS, metaclass=LoggingMixinMeta):
ONCECACHE = set()
def __new__(cls, *args):
"""
We override `__new__` in our logging logger class in order to provide
@ -233,10 +236,16 @@ class SaltLoggingClass(LOGGING_LOGGER_CLASS, metaclass=LoggingMixinMeta):
stack_info=False,
stacklevel=1,
exc_info_on_loglevel=None,
once=False,
):
if extra is None:
extra = {}
if once:
if str(args) in self.ONCECACHE:
return
self.ONCECACHE.add(str(args))
# pylint: disable=no-member
current_jid = RequestContext.current.get("data", {}).get("jid", None)
log_fmt_jid = RequestContext.current.get("opts", {}).get("log_fmt_jid", None)
@ -265,6 +274,7 @@ class SaltLoggingClass(LOGGING_LOGGER_CLASS, metaclass=LoggingMixinMeta):
exc_info_on_loglevel
)
)
# XXX: extra is never None
if extra is None:
extra = {"exc_info_on_loglevel": exc_info_on_loglevel}
else:

View file

@ -1275,6 +1275,7 @@ def _virtual(osdata):
"cannot execute it. Grains output might not be "
"accurate.",
command,
once=True,
)
return grains