Logging

Robot Framework log levels

Robot Framework has multiple log levels that control what is shown in the automatically generated log file.

Controlling Robot Framework log level with robot.yaml

The default Robot Framework log level is INFO. If you want to change the log level, use the --loglevel argument in robot.yaml. For example, here is how you use the DEBUG log level:

tasks:
  Default:
    command:
      - python
      - -m
      - robot
      - --report
      - NONE
      - --outputdir
      - output
      - --logtitle
      - Task log
      - --loglevel
      - DEBUG
      - tasks.robot

Disable all logging globally

Use the NONE log level to disable all logging (robot.yaml):

tasks:
  Default:
    command:
      - python
      - -m
      - robot
      - --report
      - NONE
      - --outputdir
      - output
      - --logtitle
      - Task log
      - --loglevel
      - NONE
      - tasks.robot

Disable logging for individual keywords

Use the Register Protected Keywords keyword from the RPA.RobotLogListener library to disable logging for individual keywords. See the example robot below.

Flatten keywords

Flattening keywords is done already when the output file is parsed initially. This can save a significant amount of memory especially with deeply nested keyword structures. The --flattenkeywords option flattens matching keywords. In practice this means that matching keywords get all log messages from their child keywords, recursively, and child keywords are discarded otherwise.

Remove keywords

Removing keywords is done after parsing the output file and generating an internal model based on it. Thus it does not reduce memory usage as much as flattening keywords. The --removekeywords option removes keywords and their messages altogether.

Logging example robot

This robot demonstrates the effect of the global log level (robot.yaml) and shows how to disable logging for individual keywords using the RPA.RobotLogListener library:

*** Settings ***
Documentation       Demonstrates the effect of global log level (robot.yaml).
...                 Shows how to disable logging for individual keywords.
...                 https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#log-levels

Library             RPA.Browser.Selenium
Library             RPA.RobotLogListener

Task Teardown       Close All Browsers


*** Tasks ***
Use global log level (robot.yaml)
    Log in
    #
    # Log level: INFO (default)
    # -----------------------------------------------------------
    # ${username} = BuiltIn . Set Variable maria
    #
    # ${password} = BuiltIn . Set Variable thoushallnotpass
    #
    # RPA.Browser.Selenium . Input Text username, ${username}
    # Typing text 'maria' into text field 'username'.
    #
    # RPA.Browser.Selenium . Input Password password, ${password}
    # Typing password into text field 'password'.
    # Temporally setting log level to: NONE
    # Log level changed from NONE to INFO.
    #
    # Log level: NONE (disable detailed logging)
    #------------------------------------------------------------
    # ${username} = BuiltIn . Set Variable maria
    #
    # ${password} = BuiltIn . Set Variable thoushallnotpass
    #
    # RPA.Browser.Selenium . Input Text username, ${username}
    #
    # RPA.Browser.Selenium . Input Password password, ${password}

Use RPA.RobotLogListener to disable logging for individual keywords
    Register Protected Keywords    Log in
    Log in
    #
    # ${username} = BuiltIn . Set Variable maria
    #
    # ${password} = BuiltIn . Set Variable thoushallnotpass
    #
    # RPA.Browser.Selenium . Input Text username, ${username}
    #
    # RPA.Browser.Selenium . Input Password password, ${password}


*** Keywords ***
Log in
    Open Available Browser    https://robotsparebinindustries.com/
    ${username}=    Set Variable    maria
    ${password}=    Set Variable    thoushallnotpass
    Input Text    username    ${username}
    Input Password    password    ${password}

Learn more about the libraries mentioned on this page:

May 5, 2022