Skip to content

Revert "Add Other Logging Implementations" #865

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

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions launch/launch/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
from .for_loop import ForLoop
from .group_action import GroupAction
from .include_launch_description import IncludeLaunchDescription
from .log import Log
from .log import LogDebug
from .log import LogError
from .log import LogInfo
from .log import LogWarning
from .log_info import LogInfo
from .opaque_coroutine import OpaqueCoroutine
from .opaque_function import OpaqueFunction
from .pop_environment import PopEnvironment
Expand Down Expand Up @@ -55,11 +51,7 @@
'ForLoop',
'GroupAction',
'IncludeLaunchDescription',
'Log',
'LogDebug',
'LogError',
'LogInfo',
'LogWarning',
'OpaqueCoroutine',
'OpaqueFunction',
'PopEnvironment',
Expand Down
8 changes: 4 additions & 4 deletions launch/launch/actions/for_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def generate_launch_description():
<launch>
<arg name="robots" default="{name: 'robotA', id: 1};{name: 'robotB', id: 2}" />
<for_each values="$(var robots)" >
<log_info message="'$(for-var name)' id=$(for-var id)" />
<log message="'$(for-var name)' id=$(for-var id)" />
</for_each>
</launch>

Expand All @@ -104,7 +104,7 @@ def generate_launch_description():
- for_each:
iter: $(var robots)
children:
- log_info:
- log:
message: "'$(for-var name)' id=$(for-var id)"

The above examples would ouput the following log messages by default:
Expand Down Expand Up @@ -284,7 +284,7 @@ def generate_launch_description():
<launch>
<arg name="num" default="2" />
<for len="$(var num)" name="i" >
<log_info message="i=$(index i)" />
<log message="i=$(index i)" />
</for>
</launch>

Expand All @@ -298,7 +298,7 @@ def generate_launch_description():
len: $(var num)
name: i
children:
- log_info:
- log:
message: i=$(index i)

The above examples would ouput the following log messages by default:
Expand Down
133 changes: 0 additions & 133 deletions launch/launch/actions/log.py

This file was deleted.

49 changes: 45 additions & 4 deletions launch/launch/actions/log_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,50 @@

"""Module for the LogInfo action."""

import warnings
from typing import List

from .log import LogInfo as LogInfo # noqa: F401
import launch.logging

# TODO: Remove log_info.py for Release after L-turtle release
warnings.warn('importing from log_info.py is deprecated; import LogInfo from log.py instead.')
from ..action import Action
from ..frontend import Entity
from ..frontend import expose_action
from ..frontend import Parser # noqa: F401
from ..launch_context import LaunchContext
from ..some_substitutions_type import SomeSubstitutionsType
from ..substitution import Substitution
from ..utilities import normalize_to_list_of_substitutions


@expose_action('log')
class LogInfo(Action):
"""Action that logs a message when executed."""

def __init__(self, *, msg: SomeSubstitutionsType, **kwargs):
"""Create a LogInfo action."""
super().__init__(**kwargs)

self.__msg = normalize_to_list_of_substitutions(msg)
self.__logger = launch.logging.get_logger('launch.user')

@classmethod
def parse(
cls,
entity: Entity,
parser: 'Parser'
):
"""Parse `log` tag."""
_, kwargs = super().parse(entity, parser)
kwargs['msg'] = parser.parse_substitution(entity.get_attr('message'))
return cls, kwargs

@property
def msg(self) -> List[Substitution]:
"""Getter for self.__msg."""
return self.__msg

def execute(self, context: LaunchContext) -> None:
"""Execute the action."""
self.__logger.info(
''.join([context.perform_substitution(sub) for sub in self.msg])
)
return None
92 changes: 0 additions & 92 deletions launch/test/launch/actions/test_log.py

This file was deleted.

47 changes: 47 additions & 0 deletions launch/test/launch/actions/test_log_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2020 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for the LogInfo action class."""

from launch import LaunchContext
from launch.actions import LogInfo
from launch.utilities import perform_substitutions


def test_log_info_constructors():
"""Test the constructors for LogInfo class."""
LogInfo(msg='')
LogInfo(msg='foo')
LogInfo(msg=['foo', 'bar', 'baz'])


def test_log_info_methods():
"""Test the methods of the LogInfo class."""
launch_context = LaunchContext()

log_info = LogInfo(msg='')
assert perform_substitutions(launch_context, log_info.msg) == ''

log_info = LogInfo(msg='foo')
assert perform_substitutions(launch_context, log_info.msg) == 'foo'

log_info = LogInfo(msg=['foo', 'bar', 'baz'])
assert perform_substitutions(launch_context, log_info.msg) == 'foobarbaz'


def test_log_info_execute():
"""Test the execute (or visit) of the LogInfo class."""
log_info = LogInfo(msg='foo')
launch_context = LaunchContext()
assert log_info.visit(launch_context) is None
Loading