I am utilizing robot framework's KubeLibrary to interact with my k8s cluster.
By default, any function and response is automatically logged to DEBUG in robot framework, meaning that it's response will be visible in the log.html that robot framework generates.
I want to disable this logging for some parts of my code or remove it afterwards somehow, e.g. I don't want the secrets to be part of the log.html regardless of log level.
Current implementation which includes response in log.html when viewing DEBUG.
from KubeLibrary import KubeLibrary
...
def some_keyword():
instance.kube = KubeLibrary(kube_config=instance.kubeconfig)
secrets_matching_secret_name = instance.kube.get_secrets_in_namespace(
name_pattern=f"^{secret_name}$",
namespace=namespace
)
Wishful skeleton code for how it could be done
instance.kube = KubeLibrary(kube_config=instance.kubeconfig)
instance.kube.disable_debug_log()
secrets_matching_secret_name = instance.kube.get_secrets_in_namespace(
name_pattern=f"^{secret_name}$",
namespace=namespace
)
instance.kube.enable_debug_log()
Is there any way I can disable it? Or somehow filter it out from log.html using rebot or similar?
I've been dealing with this exact issue in Robot Framework + KubeLibrary. After trying several approaches, here's what actually worked for me:
import logging
from contextlib import contextmanager
@contextmanager
def suppress_debug_logging():
"""Temporarily suppress DEBUG level logging to keep secrets out of Robot logs."""
# Store original log levels here
original_levels = {}
for name, logger in logging.root.manager.loggerDict.items():
if isinstance(logger, logging.Logger):
original_levels[name] = logger.level
logger.setLevel(logging.INFO)
# Handle root logger too
root_level = logging.root.level
logging.root.setLevel(logging.INFO)
try:
yield # Run here the code that shouldn't be debug-logged
finally:
for name, level in original_levels.items():
logging.getLogger(name).setLevel(level)
logging.root.setLevel(root_level)
# Usage example:
def some_keyword():
instance.kube = KubeLibrary(kube_config=instance.kubeconfig)
with suppress_debug_logging():
secrets_matching_secret_name = instance.kube.get_secrets_in_namespace(
name_pattern=f"^{secret_name}$",
namespace=namespace
)
This approach works because KubeLibrary uses Python's standard logging module before Robot Framework gets a chance to capture the logs. By temporarily bumping the log level from DEBUG to INFO for all loggers, you prevent the sensitive data from being logged.
I tried robot's Set Log Level keyword first, but that didn't work since it only affects Robot's own logging not the underlying Python logging. The rebot approach is too blunt / you lose the entire keyword entry rather than just hiding the sensitive parts.
One thing to watch out for: if your KubeLibrary is using a logger with a custom name, you might need to adjust the logging level directly for that logger.
If you're running into issues with this approach, let me know your specific version of KubeLibrary and I can suggest maybe more