Format option for "log to console"
Fixes
@@ -3022,26 +3022,37 @@ class _Misc(_BuiltInBase):
else:
yield value
- def log_to_console(self, message, stream='STDOUT', no_newline=False):
+ def log_to_console(self, message, stream='STDOUT', no_newline=False, format=''):
"""Logs the given message to the console.
By default uses the standard output stream. Using the standard error
- stream is possibly by giving the ``stream`` argument value ``STDERR``
+ stream is possible by giving the ``stream`` argument value ``STDERR``
(case-insensitive).
By default appends a newline to the logged message. This can be
disabled by giving the ``no_newline`` argument a true value (see
`Boolean arguments`).
+ By default adds no alignment formatting. The ``format`` argument allows,
+ for example, alignment and customized padding of the log message. Please see the
+ [https://docs.python.org/3/library/string.html#formatspec|format specification] for
+ detailed alignment possibilities. This argument is new in Robot
+ Framework 5.0.
+
Examples:
| Log To Console | Hello, console! | |
| Log To Console | Hello, stderr! | STDERR |
| Log To Console | Message starts here and is | no_newline=true |
| Log To Console | continued without newline. | |
+ | Log To Console | center message with * pad | format=*^60 |
+ | Log To Console | 30 spaces before msg starts | format=>30 |
This keyword does not log the message to the normal log file. Use
`Log` keyword, possibly with argument ``console``, if that is desired.
"""
+ if format:
+ format = "{:" + format + "}"
+ message = format.format(message)
logger.console(message, newline=is_falsy(no_newline), stream=stream)
@run_keyword_variant(resolve=0)
