mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Add configurable blacklist filtering for python logger
This commit is contained in:
parent
635036fb62
commit
7be8079bad
2 changed files with 18 additions and 0 deletions
|
@ -710,6 +710,14 @@ DEFAULT_LOG_PATH:
|
||||||
ini:
|
ini:
|
||||||
- {key: log_path, section: defaults}
|
- {key: log_path, section: defaults}
|
||||||
type: path
|
type: path
|
||||||
|
DEFAULT_LOG_FILTER:
|
||||||
|
name: Name filters for python logger
|
||||||
|
default: []
|
||||||
|
description: List of logger names to filter out of the log file
|
||||||
|
env: [{name: ANSIBLE_LOG_FILTER}]
|
||||||
|
ini:
|
||||||
|
- {key: log_filter, section: defaults}
|
||||||
|
type: list
|
||||||
DEFAULT_LOOKUP_PLUGIN_PATH:
|
DEFAULT_LOOKUP_PLUGIN_PATH:
|
||||||
name: Lookup Plugins Path
|
name: Lookup Plugins Path
|
||||||
description: Colon separated paths in which Ansible will search for Lookup Plugins.
|
description: Colon separated paths in which Ansible will search for Lookup Plugins.
|
||||||
|
|
|
@ -47,6 +47,14 @@ except NameError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FilterBlackList(logging.Filter):
|
||||||
|
def __init__(self, blacklist):
|
||||||
|
self.blacklist = [logging.Filter(name) for name in blacklist]
|
||||||
|
|
||||||
|
def filter(self, record):
|
||||||
|
return not any(f.filter(record) for f in self.blacklist)
|
||||||
|
|
||||||
|
|
||||||
logger = None
|
logger = None
|
||||||
# TODO: make this a logging callback instead
|
# TODO: make this a logging callback instead
|
||||||
if C.DEFAULT_LOG_PATH:
|
if C.DEFAULT_LOG_PATH:
|
||||||
|
@ -56,6 +64,8 @@ if C.DEFAULT_LOG_PATH:
|
||||||
mypid = str(os.getpid())
|
mypid = str(os.getpid())
|
||||||
user = getpass.getuser()
|
user = getpass.getuser()
|
||||||
logger = logging.getLogger("p=%s u=%s | " % (mypid, user))
|
logger = logging.getLogger("p=%s u=%s | " % (mypid, user))
|
||||||
|
for handler in logging.root.handlers:
|
||||||
|
handler.addFilter(FilterBlackList(C.DEFAULT_LOG_FILTER))
|
||||||
else:
|
else:
|
||||||
print("[WARNING]: log file at %s is not writeable and we cannot create it, aborting\n" % path, file=sys.stderr)
|
print("[WARNING]: log file at %s is not writeable and we cannot create it, aborting\n" % path, file=sys.stderr)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue