From 1784f2772430dd53b2520db97701ce872221ae3c Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 12 Dec 2023 13:22:06 +0100 Subject: [PATCH 1/4] update docs for configuring logging formats Signed-off-by: Marc Bestmann --- .../Concepts/Intermediate/About-Logging.rst | 46 +++++++++++++++++++ .../Logging-and-logger-configuration.rst | 18 +------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/source/Concepts/Intermediate/About-Logging.rst b/source/Concepts/Intermediate/About-Logging.rst index f0bfc75bf6..a78bcb807f 100644 --- a/source/Concepts/Intermediate/About-Logging.rst +++ b/source/Concepts/Intermediate/About-Logging.rst @@ -108,6 +108,52 @@ For each of the environment settings, note that this is a process-wide setting, If no format is given, a default of ``[{severity}] [{time}] [{name}]: {message}`` is used. +``RCUTILS_CONSOLE_OUTPUT_FORMAT`` also supports the following escape character syntax. + +.. list-table:: + :header-rows: 1 + + * - Escape character syntax + - Character represented + * - ``\a`` + - Alert + * - ``\b`` + - Backspace + * - ``\n`` + - New line + * - ``\r`` + - Carriage return + * - ``\t`` + - Horizontal tab + +If ``launch`` is used to start a node, it will also generate output to the console and log. This can also be configured using environment variables. + +* ``ROS_LAUNCH_OUTPUT_FORMAT`` - Control which extra information is added by ``launch`` to each message comming from a node. + + * ``{line}`` - The log message which is itself formated according to the ``RCUTILS_CONSOLE_OUTPUT_FORMAT``. + * ``{this.process_description.final_name}`` - The name of the corresponding logger. + * ``{this.process_description.final_cmd}`` - The command that ``launch`` used to start the node. + + If no format is given, a default of ``[{this.process_description.final_name}] {line}`` is used. + +* ``OVERRIDE_LAUNCH_PROCESS_OUTPUT`` - Control the destionation of the logging by choosing one of the following options: + + * ``screen`` - ``stdout`` and ``stderr`` are logged to the screen. + * ``log`` - ``stdout`` and ``stderr`` are logged to launch log file and ``stderr`` to the screen. + * ``both`` - Both ``stdout`` and ``stderr`` are logged to the screen and to launch main log file. + * ``own_log`` - For ``stdout``, ``stderr`` and their combination to be logged to their own log files. + * ``full`` - To have ``stdout`` and ``stderr`` sent to the screen, to the main launch log file, and their own separate and combined log files. + +* ``OVERRIDE_LAUNCH_SCREEN_FORMAT`` - This format is used to display any messages directly comming from ``launch`` (in contrast to the messages coming from nodes). + + * ``{levelname}`` - The severity level (``INFO``, ``WARN``, etc.). + * ``{name}`` - The name of the corresponding logger. + * ``{message}`` - The actual message. + * ``{created:.7f}`` - The time stamp (in this case with seven decimal places). + + If no format is given, a default of ``[{levelname}] [{name}]: {msg}`` is used. + +* ``OVERRIDE_LAUNCH_LOG_FORMAT`` - The same as ``OVERRIDE_LAUNCH_SCREEN_FORMAT`` but for writting to the log file. If no format is given, a default of ``{created:.7f} [{levelname}] [{name}]: {msg}`` is used. Node creation ^^^^^^^^^^^^^ diff --git a/source/Tutorials/Demos/Logging-and-logger-configuration.rst b/source/Tutorials/Demos/Logging-and-logger-configuration.rst index ea2735d6db..cf2576a297 100644 --- a/source/Tutorials/Demos/Logging-and-logger-configuration.rst +++ b/source/Tutorials/Demos/Logging-and-logger-configuration.rst @@ -406,23 +406,7 @@ For example, to additionally get the timestamp and location of the log calls, st You should see the timestamp in seconds and the function name, filename and line number additionally printed with each message. *The ``time`` option is only supported as of the ROS 2 Bouncy release.* -``RCUTILS_CONSOLE_OUTPUT_FORMAT`` also supports the following escape character syntax. - -.. list-table:: - :header-rows: 1 - - * - Escape character syntax - - Character represented - * - ``\a`` - - Alert - * - ``\b`` - - Backspace - * - ``\n`` - - New line - * - ``\r`` - - Carriage return - * - ``\t`` - - Horizontal tab +See :doc:`Logging and logger configuration <../../Concepts/Intermediate/About-Logging>` for more details on how to configure the logging. Console output colorizing ^^^^^^^^^^^^^^^^^^^^^^^^^ From 77e0f37c69992727573dd0cea205005324658cf2 Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 23 Jan 2024 11:03:50 +0100 Subject: [PATCH 2/4] add docs for ANSI escape sequence Signed-off-by: Marc Bestmann --- .../Concepts/Intermediate/About-Logging.rst | 6 +++++ .../Logging-and-logger-configuration.rst | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/source/Concepts/Intermediate/About-Logging.rst b/source/Concepts/Intermediate/About-Logging.rst index a78bcb807f..8d062810dd 100644 --- a/source/Concepts/Intermediate/About-Logging.rst +++ b/source/Concepts/Intermediate/About-Logging.rst @@ -125,6 +125,12 @@ For each of the environment settings, note that this is a process-wide setting, - Carriage return * - ``\t`` - Horizontal tab + * - ``\x1b`` + - ANSI escape sequence start + +The ANSI escape sequence is especially interesting to use for setting `select graphics rendition parameters `_. +This allows you to format parts of the log message in different styles for better readability. +See :doc:`Logging Demo <../../Tutorials/Demos/Logging-and-logger-configuration>` for an example. If ``launch`` is used to start a node, it will also generate output to the console and log. This can also be configured using environment variables. diff --git a/source/Tutorials/Demos/Logging-and-logger-configuration.rst b/source/Tutorials/Demos/Logging-and-logger-configuration.rst index cf2576a297..ae30fd783c 100644 --- a/source/Tutorials/Demos/Logging-and-logger-configuration.rst +++ b/source/Tutorials/Demos/Logging-and-logger-configuration.rst @@ -406,6 +406,33 @@ For example, to additionally get the timestamp and location of the log calls, st You should see the timestamp in seconds and the function name, filename and line number additionally printed with each message. *The ``time`` option is only supported as of the ROS 2 Bouncy release.* +It is also possible to change the font style of the different message parts using select graphic rendition parameters. +For example, to print the node name underlined, the message bold, and the function name faint you can use the following setting: + +.. tabs:: + + .. group-tab:: Linux + + .. code-block:: bash + + export RCUTILS_CONSOLE_OUTPUT_FORMAT="\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" + ros2 run logging_demo logging_demo_main + + .. group-tab:: macOS + + .. code-block:: bash + + RCUTILS_CONSOLE_OUTPUT_FORMAT="\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" + ros2 run logging_demo logging_demo_main + + .. group-tab:: Windows + + .. code-block:: bash + + set "\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" + ros2 run logging_demo logging_demo_main + + See :doc:`Logging and logger configuration <../../Concepts/Intermediate/About-Logging>` for more details on how to configure the logging. Console output colorizing From 2809badc49483215b8d02a703869da746138d916 Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 6 Feb 2024 09:42:46 +0100 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Tomoya Fujita Signed-off-by: Marc Bestmann --- source/Concepts/Intermediate/About-Logging.rst | 3 ++- source/Tutorials/Demos/Logging-and-logger-configuration.rst | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/Concepts/Intermediate/About-Logging.rst b/source/Concepts/Intermediate/About-Logging.rst index 8d062810dd..1dd6ffdea0 100644 --- a/source/Concepts/Intermediate/About-Logging.rst +++ b/source/Concepts/Intermediate/About-Logging.rst @@ -132,7 +132,8 @@ The ANSI escape sequence is especially interesting to use for setting `select gr This allows you to format parts of the log message in different styles for better readability. See :doc:`Logging Demo <../../Tutorials/Demos/Logging-and-logger-configuration>` for an example. -If ``launch`` is used to start a node, it will also generate output to the console and log. This can also be configured using environment variables. +If ``launch`` is used to start a node, it will also generate output to the console and log. +This can also be configured using environment variables. * ``ROS_LAUNCH_OUTPUT_FORMAT`` - Control which extra information is added by ``launch`` to each message comming from a node. diff --git a/source/Tutorials/Demos/Logging-and-logger-configuration.rst b/source/Tutorials/Demos/Logging-and-logger-configuration.rst index ae30fd783c..81216b963b 100644 --- a/source/Tutorials/Demos/Logging-and-logger-configuration.rst +++ b/source/Tutorials/Demos/Logging-and-logger-configuration.rst @@ -422,14 +422,14 @@ For example, to print the node name underlined, the message bold, and the functi .. code-block:: bash - RCUTILS_CONSOLE_OUTPUT_FORMAT="\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" + export RCUTILS_CONSOLE_OUTPUT_FORMAT="\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" ros2 run logging_demo logging_demo_main .. group-tab:: Windows .. code-block:: bash - set "\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" + set "RCUTILS_CONSOLE_OUTPUT_FORMAT=\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" ros2 run logging_demo logging_demo_main From d7f7b7baef56afcd7e458812800f3497d680b207 Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 6 Feb 2024 09:45:14 +0100 Subject: [PATCH 4/4] remove empty line Signed-off-by: Marc Bestmann --- source/Tutorials/Demos/Logging-and-logger-configuration.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/source/Tutorials/Demos/Logging-and-logger-configuration.rst b/source/Tutorials/Demos/Logging-and-logger-configuration.rst index 81216b963b..def8b0f3b3 100644 --- a/source/Tutorials/Demos/Logging-and-logger-configuration.rst +++ b/source/Tutorials/Demos/Logging-and-logger-configuration.rst @@ -432,7 +432,6 @@ For example, to print the node name underlined, the message bold, and the functi set "RCUTILS_CONSOLE_OUTPUT_FORMAT=\x1b[4m{name}\x1b[0m \x1b[1m{message}\x1b[0m \x1b[2m{function_name}\x1b[0m" ros2 run logging_demo logging_demo_main - See :doc:`Logging and logger configuration <../../Concepts/Intermediate/About-Logging>` for more details on how to configure the logging. Console output colorizing