Skip to content

Commit 2ba8c6b

Browse files
Revert "Add Other Logging Implementations (#858)"
This reverts commit b7b31c4.
1 parent b7b31c4 commit 2ba8c6b

File tree

10 files changed

+107
-322
lines changed

10 files changed

+107
-322
lines changed

launch/launch/actions/__init__.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
from .for_loop import ForLoop
2424
from .group_action import GroupAction
2525
from .include_launch_description import IncludeLaunchDescription
26-
from .log import Log
27-
from .log import LogDebug
28-
from .log import LogError
29-
from .log import LogInfo
30-
from .log import LogWarning
26+
from .log_info import LogInfo
3127
from .opaque_coroutine import OpaqueCoroutine
3228
from .opaque_function import OpaqueFunction
3329
from .pop_environment import PopEnvironment
@@ -55,11 +51,7 @@
5551
'ForLoop',
5652
'GroupAction',
5753
'IncludeLaunchDescription',
58-
'Log',
59-
'LogDebug',
60-
'LogError',
6154
'LogInfo',
62-
'LogWarning',
6355
'OpaqueCoroutine',
6456
'OpaqueFunction',
6557
'PopEnvironment',

launch/launch/actions/for_loop.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def generate_launch_description():
9191
<launch>
9292
<arg name="robots" default="{name: 'robotA', id: 1};{name: 'robotB', id: 2}" />
9393
<for_each values="$(var robots)" >
94-
<log_info message="'$(for-var name)' id=$(for-var id)" />
94+
<log message="'$(for-var name)' id=$(for-var id)" />
9595
</for_each>
9696
</launch>
9797
@@ -104,7 +104,7 @@ def generate_launch_description():
104104
- for_each:
105105
iter: $(var robots)
106106
children:
107-
- log_info:
107+
- log:
108108
message: "'$(for-var name)' id=$(for-var id)"
109109
110110
The above examples would ouput the following log messages by default:
@@ -284,7 +284,7 @@ def generate_launch_description():
284284
<launch>
285285
<arg name="num" default="2" />
286286
<for len="$(var num)" name="i" >
287-
<log_info message="i=$(index i)" />
287+
<log message="i=$(index i)" />
288288
</for>
289289
</launch>
290290
@@ -298,7 +298,7 @@ def generate_launch_description():
298298
len: $(var num)
299299
name: i
300300
children:
301-
- log_info:
301+
- log:
302302
message: i=$(index i)
303303
304304
The above examples would ouput the following log messages by default:

launch/launch/actions/log.py

-133
This file was deleted.

launch/launch/actions/log_info.py

+45-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,50 @@
1414

1515
"""Module for the LogInfo action."""
1616

17-
import warnings
17+
from typing import List
1818

19-
from .log import LogInfo as LogInfo # noqa: F401
19+
import launch.logging
2020

21-
# TODO: Remove log_info.py for Release after L-turtle release
22-
warnings.warn('importing from log_info.py is deprecated; import LogInfo from log.py instead.')
21+
from ..action import Action
22+
from ..frontend import Entity
23+
from ..frontend import expose_action
24+
from ..frontend import Parser # noqa: F401
25+
from ..launch_context import LaunchContext
26+
from ..some_substitutions_type import SomeSubstitutionsType
27+
from ..substitution import Substitution
28+
from ..utilities import normalize_to_list_of_substitutions
29+
30+
31+
@expose_action('log')
32+
class LogInfo(Action):
33+
"""Action that logs a message when executed."""
34+
35+
def __init__(self, *, msg: SomeSubstitutionsType, **kwargs):
36+
"""Create a LogInfo action."""
37+
super().__init__(**kwargs)
38+
39+
self.__msg = normalize_to_list_of_substitutions(msg)
40+
self.__logger = launch.logging.get_logger('launch.user')
41+
42+
@classmethod
43+
def parse(
44+
cls,
45+
entity: Entity,
46+
parser: 'Parser'
47+
):
48+
"""Parse `log` tag."""
49+
_, kwargs = super().parse(entity, parser)
50+
kwargs['msg'] = parser.parse_substitution(entity.get_attr('message'))
51+
return cls, kwargs
52+
53+
@property
54+
def msg(self) -> List[Substitution]:
55+
"""Getter for self.__msg."""
56+
return self.__msg
57+
58+
def execute(self, context: LaunchContext) -> None:
59+
"""Execute the action."""
60+
self.__logger.info(
61+
''.join([context.perform_substitution(sub) for sub in self.msg])
62+
)
63+
return None

launch/test/launch/actions/test_log.py

-92
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2020 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Tests for the LogInfo action class."""
16+
17+
from launch import LaunchContext
18+
from launch.actions import LogInfo
19+
from launch.utilities import perform_substitutions
20+
21+
22+
def test_log_info_constructors():
23+
"""Test the constructors for LogInfo class."""
24+
LogInfo(msg='')
25+
LogInfo(msg='foo')
26+
LogInfo(msg=['foo', 'bar', 'baz'])
27+
28+
29+
def test_log_info_methods():
30+
"""Test the methods of the LogInfo class."""
31+
launch_context = LaunchContext()
32+
33+
log_info = LogInfo(msg='')
34+
assert perform_substitutions(launch_context, log_info.msg) == ''
35+
36+
log_info = LogInfo(msg='foo')
37+
assert perform_substitutions(launch_context, log_info.msg) == 'foo'
38+
39+
log_info = LogInfo(msg=['foo', 'bar', 'baz'])
40+
assert perform_substitutions(launch_context, log_info.msg) == 'foobarbaz'
41+
42+
43+
def test_log_info_execute():
44+
"""Test the execute (or visit) of the LogInfo class."""
45+
log_info = LogInfo(msg='foo')
46+
launch_context = LaunchContext()
47+
assert log_info.visit(launch_context) is None

0 commit comments

Comments
 (0)