0

I have been googling since quite time to separate out selenium log (Automation API) debug info with application (My logging info) in two different file but automation api log is also coming on my application log file.

I tried following approach (I tried commented line too):

def get_selenium_logger():
  logger=logging.getLogger('selenium.webdriver.remote.remote_connection')
  fh = logging.FileHandler('results/selenium_log.log', delay=True)
  fh.setLevel(logging.DEBUG)
  logger.addHandler(fh)

  return logger

def get_application_logger():
  logger=logging.getLogger()
  logging.basicConfig(level=logging.DEBUG)
  fh = logging.FileHandler('results/automation_log.log', delay=True)
  fh.setLevel(logging.DEBUG)

  formatter=logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(funcName)s - %(lineno)d - %(message)s')
  fh.setFormatter(formatter)  
  #logger.removeFilter(logging.Filter('selenium.webdriver.remote.remote_connection'))
  logger.addHandler(fh)
  return logger

def my_automation_code():
  get_selenium_logger()
  app_logger = get_application_logger()
  app_logger.info("Test **************")

debug log from automation api (selenium) also listed on "automation_log.log", How can I filter it?

1
  • I updated my answer in response to your comment. Commented Jan 17, 2014 at 18:23

1 Answer 1

1

Instead of using the root logger for your application, using a logger whose name doesn't start with "selenium." to separate the two logs. For example:

def get_application_logger():
  logger=logging.getLogger('myapp')
  # rest of the stuff as in your snippet

Update: The name of your application is whatever you decide. In a module which is imported, you can use __name__ as the logger name; in a script, it can be whatever you like, e.g. the basename of the script.

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

2 Comments

Thanks for detail. It my sound weird but can you please let me know how to find out name of my app? I have root folder name and then one starting point as app_runner.py.
or we do have some kind of "." or "this" or getApp() method for it?

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.