Skip to content

Commit

Permalink
Merge pull request #98 from vpodzime/master-always_send_info
Browse files Browse the repository at this point in the history
Always send important log messages from Python-based promise types
  • Loading branch information
olehermanse authored Jun 19, 2024
2 parents 2ce7daa + 2404c7d commit 2be0eee
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions libraries/python/cfengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ def _put_response(data, file, record_file=None):
record_file.write("> \n")


def _would_log(level_set, msg_level):
def _should_send_log(level_set, msg_level):
if msg_level not in _LOG_LEVELS:
# uknown level, assume it would be logged
return True

return _LOG_LEVELS[msg_level] <= _LOG_LEVELS[level_set]
# info: log messages are special because they report changes done in promise
# evaluation which is important not only for showing to the user, but also
# for auditing/changelog and all modules are required to send info: messages
# for all REPAIRED promises. A similar logic applies to errors and warnings,
# IOW, anything at or above the info level.
return ((_LOG_LEVELS[msg_level] <= _LOG_LEVELS["info"]) or
(_LOG_LEVELS[msg_level] <= _LOG_LEVELS[level_set]))


def _cfengine_type(typing):
Expand Down Expand Up @@ -398,7 +404,7 @@ def _handle_terminate(self):
sys.exit(0)

def _log(self, level, message):
if self._log_level is not None and not _would_log(self._log_level, level):
if self._log_level is not None and not _should_send_log(self._log_level, level):
return

# Message can be str or an object which implements __str__()
Expand Down

0 comments on commit 2be0eee

Please sign in to comment.