webpy logging to separate log files webpy logging to separate log files curl curl

webpy logging to separate log files


There are two issues in your code.

You said,

I get the same logging information in subtype1.log and subtype2.log

The reason is you need to create two separate, completely different logging objects. You can do it with logging.getLogger() by passing the name you want.

In your case it should be self._log = logging.getLogger(self.logfile)

  1. The logs get duplicated when you call them multiple times. (You have not noticed it but that issue is there in your code.)

The reason is logging.getLogger() is a singleton. So every time you create an instance of Class C it adds another handler to the instance which causes the duplication of logs.So I have checked if not len(self._log.handlers): before adding the handler.

So your final test_classC.py is as follows,

# test_classC.pyimport loggingclass classC:    def __init__(self, subtype):        self.nw_type = subtype        self.logfile = subtype + '.log'        self._log = logging.getLogger(self.logfile)        if not len(self._log.handlers):            self._log.setLevel(logging.INFO)            self.handler = logging.FileHandler(self.logfile)            self._log.addHandler(self.handler)    def logsomething(self):        self._log.info("This is network type: %s" %self.nw_type)

To test the parallel requests you can use jmeter