1

Issue: Unable to get all the log types printed in console and none at log file while invoking below log methods via robot files.

import logging
from colorlog import ColoredFormatter

class Log():
    LOG_LEVEL = logging.DEBUG
    LOGFORMAT = "  %(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s"
    logging.root.setLevel(LOG_LEVEL)
    formatter = ColoredFormatter(LOGFORMAT)
    stream = logging.StreamHandler()
    stream.setLevel(LOG_LEVEL)
    stream.setFormatter(formatter)
    Log = logging.getLogger('pythonConfig')
    Log.setLevel(LOG_LEVEL)
    Log.addHandler(stream)

    logger = logging.getLogger(__name__)
    logging.basicConfig(
        filename='c://foo//app.log',
        format='%(asctime)s - %(levelname)s: %(message)s',
        datefmt='%d-%b-%y %H:%M:%S', level=logging.INFO,
    )

    @classmethod
    def warn(cls, message):
        cls.Log.warning(message)

    @classmethod
    def info(cls, message):
        cls.Log.info(message)

    @classmethod
    def error(cls, message):
        cls.Log.error(message)

    @classmethod
    def debug(cls, message):
        cls.Log.debug(message)

# Calling class methods

Log.warn("test")
Log.info("test")
Log.error("test")
Log.debug("test")

Running using python from command prompt:-

C:foo>py log.py

  WARNING  | test
  INFO     | test
  ERROR    | test
  DEBUG    | test

app.log

01-Sep-19 21:32:31 - WARNING: test
01-Sep-19 21:32:31 - INFO: test
01-Sep-19 21:32:31 - ERROR: test
01-Sep-19 21:32:31 - DEBUG: test

When I invoke the same methods via robot file (Python >> Robot suite), I am unable to get any of the logs printed in log file (app.log) and could see only error and warning messages are printed in console. could someone help me in this regards?

Runner.py

import robot

logFile = open('c:\\foo\\ExecutionReport.txt','w')
htmlpath = "c:\\foo\\Reports.html"
robot.run("c:\\foo\\test_sample.robot", log=None,report=htmlpath, output=None,
          stdout=logFile)

Robot:-

*** Settings ***
Library  ../Robot/Log.py

*** Test Cases ***
testinglogger
    info  test
    error  test
    debug  test
    warn  test

app.log: None

enter image description here

2
  • could someone help me on this regards? Commented Sep 2, 2019 at 14:36
  • Any assistance? Commented Sep 29, 2019 at 13:52

1 Answer 1

1

In the Python Runner.py script you are invoking the robot.run function and setting some parameters for the execution, such as log=None and output=None. This causes no log files to be created (no output) and no logging to be visible (outside of ERROR and WARN apparently.).

See these Robot Framework run parameters:

-o --output file where file is the name of the Robot output. Setting NONE to this causes also reports and all other file logging to be disabled.

Leave unassigned to create default log files for Robot Framework. I believe this maps to the robot.run command's output parameter.

-L --loglevel level where level is the desired lowest logging level.

Available levels: TRACE, DEBUG, INFO (default), WARN, NONE (no logging). In this case you probably want to set it to DEBUG

Make the required changes to your Runner.py script and try again :)

Here is the complete documentation for the latest version 3.1.2 Robot Framework's robot.run script:

https://robot-framework.readthedocs.io/en/v3.1.2/_modules/robot/run.html

Sign up to request clarification or add additional context in comments.

2 Comments

I have edited as per your suggestion but still not getting log file updated robot.run("C:\\foo\\test_sample.robot", log=log, report=report, output=output, loglevel=logging.DEBUG, stdout=exec_report)
Any further assistance?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.