Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to enable or disable logs through service call #2256

Open
wants to merge 1 commit into
base: melodic-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions clients/rospy/src/rospy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,23 @@ def _get_loggers(request):
'ERROR': logging.ERROR,
'FATAL': logging.CRITICAL,
}
_level_to_change_logs = {
"ENABLE": logging.NOTSET,
"DISABLE": logging.CRITICAL
}

def _set_logger_level(request):
"""
ROS service handler to set the logging level for a particular logger
"""
level = request.level.upper()
if level in _names_to_logging_levels:
logger = logging.getLogger(request.logger)
logger_request = request.logger
if logger_request.upper() in _level_to_change_logs:
logging.disable(_level_to_change_logs[logger_request.upper()])
elif level in _names_to_logging_levels:
logger = logging.getLogger(logger_request)
if(not logger.isEnabledFor(logging.CRITICAL)):
logging.disable(_level_to_change_logs["ENABLE"])
logger.setLevel(_names_to_logging_levels[level])
else:
logging.getLogger('rospy').error("Bad logging level: %s"%level)
Expand Down