Skip to content

Add --log-level alias to ros2 log watch #1307

Description

@sloretz

ros2 component uses --log-level to specify the log severity level, whereas ros2 log watch uses --level.

Modify ros2log/ros2log/verb/watch.py to accept --log-level as an alias for --level:

  • ros2log/ros2log/verb/watch.py

Example: How to add the alias

Keep '--level' first (so args.level continues to work without changing the rest of the file) and add '--log-level':

# Before:
parser.add_argument(
    '--level',
    choices=['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL',
             'debug', 'info', 'warn', 'error', 'fatal'],
    help='Show only logs at or above the specified severity level')

# After:
parser.add_argument(
    '--level', '--log-level',
    choices=['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL',
             'debug', 'info', 'warn', 'error', 'fatal'],
    help='Show only logs at or above the specified severity level')

Example: How to add a test

Add a test in ros2log/test/test_watch.py to verify that --log-level populates args.level:

import argparse
from ros2log.verb.watch import WatchVerb


def test_watch_log_level_alias():
    parser = argparse.ArgumentParser()
    verb = WatchVerb()
    verb.add_arguments(parser, 'ros2 log watch')
    args = parser.parse_args(['--log-level', 'WARN'])
    assert args.level == 'WARN'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions