Skip to content

Control logging of executed keywords #2603

Closed as not planned
Closed as not planned

Description

@VernonCrabtree

Currently, all executed keywords are added as a node in the robot framework XML output.
Logged output from these keywords can be controlled with Log level, but the keyword itself cannot be turned off except with external command line options.
There are several issues with this:

  • If passwords are part of the keyword or parameters, this might be logged.
  • A user library might want to make repeated use of user-defined keywords (using BuiltIn.run_keyword), but logging of each repetition not wanted.
  • It is currrently possible to flatten/remove by keyword name and/or by tags, but this must be explicitly specified when running robot or rebot. This proposal makes this up to the keyword implementation to decide.

This proposal is to introduce special tags like robot:flatten - for example:

*** Keywords *** 
Example 
    [Tags]    robot:flatten 
    Some keyword 
    Another keyword

In this case, keywords "Some keyword" and "Another keyword" do not appear in the log.
The output from these keywords still obey the current log level.

It could be that several special tags are needed - such as robot:flatten-this-keyword and robot:flatten-recursive, so that the implementor can choose whether the implemented keyword is logged and whether called keywords are logged.

Another thought is to enable programmatic/robot framework script use of the --flattenkeywords option so that it applies to the current scope.

Please offer any ideas for implementation.

Activity

  1. pekkaklarck commented on May 25, 2017

    @pekkaklarck
    Member

    Yeah, this would be a nice enhancement. One big benefit is reducing the size of the generated output.xml and log.html files. This also saves time processing output.xml.

    In my opinion we should start with just robot:flatten tag and it should be recursive. Once we got it implemented, we can see would robot:no-flatten (also recursive) be useful too.

    I don't have time to look at the code more closely right now, but I would assume implementing this requires basically these steps:

    1. Either implement a special XmlLogger class (this one is responsible on writing output.xml) that doesn't write any information when keywords are started and stopped or enhance the current XmlLogger so that it can be externally configured to stop logging keyword start/stop.

    2. When starting a keyword execution, change XmlLogger to stop logging keyword start/stop. When that keyword finishes, restore the old behavior.

    One thing to decide is that should flattening affect already the keyword that has robot:flatten or only the internal keywords. In other words, should that keyword still be visible in the log file or not. I got a feeling that it should.

  2. VernonCrabtree commented on Jul 3, 2018

    @VernonCrabtree
    Author

    I have created a branch of robot framework: https://github.com/VernonCrabtree/robotframework
    I am not entirely happy with it yet, but so far it has these features:

    • As discussed, keywords with the tag "flatten" are not logged.
    • Keywords can be prefixed with 2 directive characters from the set '+-'. The first is an instruction regarding logging of this call, the second instruct about the logging of all keywords called by this keyword. + = definitely log, - = don't log. Using * is to accept the current previous setting, so instruction like "+My logged keyword" can be used.
    • Keywords can be prefixed with a single character '-' or '+'. '-' causes the keyword to not be logged but called keywords will be logged. '+' over-rides the current logging directive and logs this keyword anyway. A single '*' can be used, but has no effect.

    I had a plan to be able to log a block of keywords under a single self-defined keyword name, but then this is green in the log instead of red if the test fails. I am thinking this should be removed anyway.

    The new features need good tests added in the testing of Robot Framework and I am a bit confused for now how these are implemented - there are techniques for validating the logged keywords that I need to use by the looks of it.

    Please, could I have some advice on how to proceed so I can't respond fast - I don't have so much time anymore. Maybe in the next holidays. By now I probably at least have to rebase against the robot framework master repository.

    Finally, please let me know if this is the right communication forum for this level of questions or is there a better channel to use?
    Thank you for the great framework.

  3. nsavelyeva commented on Jun 21, 2019

    @nsavelyeva

    Hi,
    Is there any progress on this or is it cancelled finally?

  4. VernonCrabtree commented on Jun 21, 2019

    @VernonCrabtree
    Author

    Natallia,
    Thank you for your query - I have not had a lot of interest in this subject, none in fact.
    I still think it is important - but I keep getting drawn in to operational test activities. In terms of Robot Framework, there are also plenty of other higher-priority enhancements.
    Lately I have had a bit more time due to extensive use of the work "NO" - to work on more strategic activities! I have also learned a whole lot about how to use Git properly, so I should give it another go.
    If you could give me some feedback about the proposed approach, that would help me a lot.
    If you could help testing and/or documenting that would also help.
    What do you think?

  5. nsavelyeva commented on Jun 24, 2019

    @nsavelyeva

    Hi @VernonCrabtree
    Thanks for your reply.
    I think we should stick to @pekkaklarck advice above and "robot:flatten", "robot:flatten-recursive" and similar is enough, there is no need of prefixes +- to keywords names.
    I can help with documentation and testing new functionality manually, because I am not sure how RF is tested, I mean CI/CD pipelines, etc.

  6. pekkaklarck commented on Jun 24, 2019

    @pekkaklarck
    Member

    This is still considered an important issue, but because there are also other important issues and only very limited development resources, it's currently not scheduled to any release. External development help would be great, but this is rather big task and requires digging quite deep into Robot's code. Definitely nit impossible task if someone is interested.

    Sponsoring the development is another possibility. That can be either directly by paying me or someone to implement this, or by joining Robot Framework Foundation that sponsors the development in general.

  7. pekkaklarck commented on Aug 16, 2019

    @pekkaklarck
    Member

    This is to some extend related to #2285 that proposes adding robot:continue-on-failure tag to control how keywords should behave if there are failures.

  8. pekkaklarck commented on Apr 8, 2020

    @pekkaklarck
    Member

    The tag should probably be robot:flatten-keywords to make it more explicit what it does. Same naming convention would also work with robot:remove-keywords. I'm not entirely sure about the s at the end, but perhaps it's a good idea because this tag really affects the internal keywords, not the keyword that has the tag.

  9. VernonCrabtree commented on Apr 8, 2020

    @VernonCrabtree
    Author

    When developing a keyword, I can choose python (or other language) or I can write user-defined keywords. I have often found it faster to implement functionality in Robot Framework because of faster developer feedback via the logging.
    I have sometimes decided to reimplement user defined keywords in python for performance reasons, but often the main performance bottleneck is this logging and just turning off the logging could be enough.
    There are times when we don't want a keyword logged and times that we do want it logged. This can happen in the same script. As an example, a base-level keyword is "Log": I might want information split into separate Log entries in the output, or I might want all the output logging directly under my user-defined keyword. I might even want to mix-and-match within the keyword. But as a developer, I should be in control of the output logging.
    I want to be able to choose for each call whether the keyword and its called keywords are logged or not. Putting a tag on the keyword does not achieve this. This is why I thought of the notation above. The passing of information between the parser and the logger as well as maintaining a call stack was complex. This may have changed in recent versions.

    I think you are right about starting simple - Just one tag (or maybe 2), review how well it works and then proceed from there. But I would like to understand how to get to the flexible situation I describe here.

    I will take another look over the next few weeks.

  10. VernonCrabtree commented on May 3, 2020

    @VernonCrabtree
    Author

    OK - having submitted a pull request for passing of arguments into tags, now I am back to the logging control.
    First, a documentation review.
    rebot --removekeywords requires an argument. One of ALL, PASSED, FOR, WUKS, NAME:, TAG: and the documentation says it removes all the messages as well. This is different from what we want here but it could be something we want to work with. Since we are defining a keyword, the identification of which keywords we want to target is not necessary.
    rebot --flattenkeywords keeps the log messages and recurses the called keywords. This is desirable in some cases, but does not cover the situation where we want to hide the call to this keyword but log the called keywords. We could use this for the matching use-case and create a new tag name for hiding just this keyword.

    The tag solution is good for user-defined keywords, but what if I want to use say "RUN KEYWORD" but not have RUN KEYWORD logged as a keyword. This is annoying because we have to click through to the keyword to see what keyword was run and in consumes disk space and processing.
    A new keyword, which optionally does not get logged, could be introduced: RUN KEYWORD WITH TAGS, or something like that.

    To be continued . . .

  11. pekkaklarck commented on May 4, 2020

    @pekkaklarck
    Member

    We'd probably need both robot:flatten (same as --flattenkeywords) and robot:remove (same as --removekeywords). To make these tags easier to understand, naming them robot:flatten-keywords and robot:remove-keywords might be a good idea.

    I don't like adding new Run Keyword variants that much, but we can discuss would it make sense in this use case. That would require a separate issue, though.

  12. VernonCrabtree commented on May 6, 2020

    @VernonCrabtree
    Author

    When a keyword is started, we need to know not to log the keyword start in the logged output (so not call logger.start on each logger).
    When the keyword is ended, we conversely need to know that we didn't start, so we do not need to end each keyword.
    Because keywords call other keywords, we need to retain this information in a stack of some sort.
    This becomes more critical when we consider failure scenarios.
    Question is, with the refactoring of how keywords are run, will there be a keyword context stack on which we can store this information and access it from the logger, or is it simpler just to do this separately in the logger?

  13. pekkaklarck commented on May 6, 2020

    @pekkaklarck
    Member

    This change only affects Robot's logger that writes output.xml. This could probably be implemented by creating different XmlLogger variants for different usages and switching that when needed. Or perhaps XmlLogger could have an externally controlled state that controls what's actually written.

    As you mentioned, the execution side is going to be pretty heavily refactored before the next RF major version. Implementing this before that is possible only if changes aren't too big or complex.

  14. VernonCrabtree commented on May 6, 2020

    @VernonCrabtree
    Author

    Oh yea - that reminds me of the other design consideration:
    Should the logging control tags affect just the XML Log output, or all log output (listeners and so forth)? My idea is all log outputs - so a keyword's logging is suppressed everywhere. However, your idea seems to be specific to the XmlLogger.
    To support multiple variants of different loggers as efficiently as possible, I think I will take your suggestion of an externally controlled state.
    Would you prefer this to be part of logger.py or should I write a separate module? I don't think it is a lot of code.

  15. pekkaklarck commented on May 6, 2020

    @pekkaklarck
    Member

    The problem this issue tries to solve is with output.xml (and log.html created based on that). I'd concentrate on that simply because it's a lot less work. There could also be downsides of disabling logging e.g. with listeners in this case.

    I haven't looked at the code (and don't have time for that right now) to be able to comment what should be changed. If we go with altering XmlLogger state, changes could be pretty small and isolated. Go ahead and prototype and show the code when you have something ready. Doesn't need to be a PR in the first phase, just a link to a branch with changes is enough.

  16. pekkaklarck commented on Oct 16, 2021

    @pekkaklarck
    Member

    On our Slack someone proposed this kind of functionality and I mentioned this already somewhat old issue. Since I last commented here, issue #2603 adding support to control the continue-on-failure mode using tags has been implemented so we have an example that tags works well in this kind of usage.

    My current thinking about how this issue should be implemented is as follows:

    • I believe we only need flattening at least in the beginning. Removing keywords can make it harder to debug failed tests. Removing keywords only if tests pass would require keeping information in memory and writing it to output.xml when tests end. which is harder to implement.
    • The tag should be robot: flatten. If we add removing, robot: remove is fine
    • No need for robot: no-flatten at least in the beginning.
    • This is probably easiest to implement by XmlLogger having state controlling should keywords be flattened ot not. Flattening would basically mean not doing anything in start_keyword and end_keyword. That would be easy.
  17. pekkaklarck commented on Jan 3, 2023

    @pekkaklarck
    Member

    I forgot we already had this issue and submitted #4584 about robot:flatten. The description has lot of information about flattening in general and also has a pretty concrete design proposal (with some open issues). I think it's better to keep that issue open so I close this one as its duplicate. Anyway, there's a good change this is implemented in somewhat near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions