diff --git a/tomwer/web/client.py b/tomwer/web/client.py index 04fb856b44f56e1be02c3b3dd45f951257fc2a9c..a9f1ec56b9ee96de15487295a98df5e77d92510e 100644 --- a/tomwer/web/client.py +++ b/tomwer/web/client.py @@ -1,5 +1,5 @@ # coding: utf-8 -#/*########################################################################## +# /*########################################################################## # Copyright (C) 2016 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -30,7 +30,6 @@ __authors__ = ["H.Payno"] __license__ = "MIT" __date__ = "28/04/2017" - import graypy from .config import grayport_port, grayport_host import os @@ -39,9 +38,11 @@ import logging _logger = logging.getLogger(__file__) +global _INFO_UNKNOWN_HOST_NAME _INFO_UNKNOWN_HOST_NAME = False """Cache variable to avoid several log about this information""" + class OWClient(object): """Orange widget Client can emit information about his advancement """ @@ -51,19 +52,22 @@ class OWClient(object): def __init__(self, loggers): assert loggers is not None - if self._knows_hostname(hostname=grayport_host) is False: + if OWClient._knows_hostname(hostname=grayport_host) is False: + global _INFO_UNKNOWN_HOST_NAME if _INFO_UNKNOWN_HOST_NAME is False: _logger.warning('unknow host %s' % grayport_host) _INFO_UNKNOWN_HOST_NAME = True return if type(loggers) not in (list, tuple): - loggers = (loggers, ) + loggers = (loggers,) for logger in loggers: if os.environ.get('ORANGE_WEB_LOG', 'True') is 'True': try: - self.graylogHandler = graypy.GELFHandler(grayport_host, grayport_port) + self.graylogHandler = graypy.GELFHandler(grayport_host, + grayport_port) except: - logger.error('Fail to create GELFHandler. Won\'t report log message') + logger.error( + 'Fail to create GELFHandler. Won\'t report log message') else: logger.addHandler(self.graylogHandler) logger.debug('- add graypy handler') @@ -72,7 +76,8 @@ class OWClient(object): info += 'ORANGE_WEB_LOG variable is setted to False' logger.info(info) - def _knows_hostname(self, hostname): + @staticmethod + def _knows_hostname(hostname): try: socket.gethostbyname(hostname) return True