Description
Introduction
With nested keyword structures, especially with recursive keyword calls and with WHILE and FOR loops, the log file can get hard do understand with many different nesting levels. Such nested structures also increase output.xml size, because even a simple keyword like
*** Keywords ***
Keyword
Log Robot
Log Frameworkcreates this much content:
<kw name="Keyword">
<kw name="Log" library="BuiltIn">
<arg>Robot</arg>
<doc>Logs the given message with the given level.</doc>
<msg timestamp="20230103 20:06:36.663" level="INFO">Robot</msg>
<status status="PASS" starttime="20230103 20:06:36.663" endtime="20230103 20:06:36.663"/>
</kw>
<kw name="Log" library="BuiltIn">
<arg>Framework</arg>
<doc>Logs the given message with the given level.</doc>
<msg timestamp="20230103 20:06:36.663" level="INFO">Framework</msg>
<status status="PASS" starttime="20230103 20:06:36.663" endtime="20230103 20:06:36.664"/>
</kw>
<status status="PASS" starttime="20230103 20:06:36.663" endtime="20230103 20:06:36.664"/>
</kw>We have had --flattenkeywords option for "flattening" such structures since RF 2.8.2 (#1551) and it works great. When a keyword is flattened, its child keywords and control structures are removed otherwise, but all their messages are preserved. It doesn't affect output.xml generated during execution, but flattening happens when output.xml files are parsed and can save huge amounts of memory. When --flattenkeywords is used with Rebot, it is possible to create a new flattened output.xml. For example, the above structure is converted into this if Keyowrd is flattened:
<kw name="Keyword">
<doc>_*Content flattened.*_</doc>
<msg timestamp="20230103 20:06:36.663" level="INFO">Robot</msg>
<msg timestamp="20230103 20:06:36.663" level="INFO">Framework</msg>
<status status="PASS" starttime="20230103 20:06:36.663" endtime="20230103 20:06:36.664"/>
</kw>
Proposal
Flattening works based on keyword names and based on tags, but it needs to be activated separately from the command line. This issue proposes adding new built-in tag robot:flatten that activates this behavior automatically. Removing top level keywords from tests and leaving only their messages doesn't make sense, so robot:flatten should be usable only as a keyword tag.
This functionality should work already during execution so that flattened keywords and control structures are never written to output.xml file. This avoid output.xml file growing big and is likely to also enhance the performance a bit.
Open questions
There are some open questions related to the design still:
- Should
start/end_keywordlistener methods be called with flattened keywords? I believe not, but I don't feel too strongly about this. - Should we add Content flattened to keyword documentation like we do with
--flattenkeywords? I believe not. There's therobot:flattentag to indicate that anyway. - Should
--flattenkeywordsbe changed to work during execution as well? I believe yes, but that requires a separate issue. - Should automatic TRACE level logging of arguments and return values of flattened keywords be disabled? I believe yes, but this isn't high priority.
Possible future enhancements
--flattenkeywords allows flattening WHILE or FOR loops or all loop iterations. Something like that would be convenient with built-in tags as well. We could consider something like robot:flatten:while and robot:flatten:iteration to support that, but I believe that's something that can wait until future versions.
Another alternative would be allowing tags with control structures as shown in the example below. This would require parser and model changes but could also have other use cases. That's certainly out of the scope of RF 6.1, though.
*** Keywords ***
Keyword
WHILE True
[Tags] robot:flatten
Nested
END
Activity
Implement robot:flatten keyword tag
Implement robot:flatten keyword tag
Implement robot:flatten keyword tag
Implement robot:flatten keyword tag
Implement robot:flatten keyword tag
Implement robot:flatten keyword tag
doc: document robot:flatten keyword tag