Skip to content

Commit

Permalink
Avoid repeatedly allocating StreamHandler for SandeshLogger
Browse files Browse the repository at this point in the history
Note: Backported from master

Change-Id: I37dd478eaedd1dcb182f8819c426fe940dc4bb03
Closes-Bug: #1405245
  • Loading branch information
anbu-enovance committed Jan 8, 2015
1 parent 657aab6 commit ffd40b9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions library/python/pysandesh/sandesh_logger.py
Expand Up @@ -41,11 +41,15 @@ def __init__(self, generator):
self._logger = logging.getLogger(self._generator)
self._logging_level = SandeshLevel.SYS_INFO
self._logger.setLevel(self._SANDESH_LEVEL_TO_LOGGER_LEVEL[self._logging_level])
self._logging_file_handler = logging.StreamHandler()
log_format = logging.Formatter('%(asctime)s [%(name)s]: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
self._logging_file_handler.setFormatter(log_format)
self._logger.addHandler(self._logging_file_handler)
if not len(self._logger.handlers):
# add the handler only once
self._logging_file_handler = logging.StreamHandler()
log_format = logging.Formatter('%(asctime)s [%(name)s]: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
self._logging_file_handler.setFormatter(log_format)
self._logger.addHandler(self._logging_file_handler)
else:
self._logging_file_handler = self._logger.handlers[0]
#end __init__

def logger(self):
Expand Down

0 comments on commit ffd40b9

Please sign in to comment.