在设置器中使用日志记录会阻止实际的日志输出

时间:2019-02-07 21:12:58

标签: python-3.x logging decorator

我解决了我的问题,但我首先不理解是什么原因导致了问题。

cherrypy.config.update({'server.socket_host': '0.0.0.0',
                        'server.socket_port': 9090,
                        })

class DekkoServer(object):

    def __init__(self):

        self.dataSources = {}

        ### Logging
        self.log_path = './logs/server/'
        self.timestamp_str = str(datetime.now())
        self.log_lvl = logging.DEBUG

        logging.basicConfig(filename=self.log_path + 'log_srv-' + self.timestamp_str, level=self.log_lvl)
        logging.info("LOGGING LEVEL: " + str(self.log_lvl))

        #cherrypy.log.error_log.propagate = False
        #cherrypy.log.access_log.propagate = False

    @cherrypy.expose
    def index(self):
        return "Dekko Server Index"

    @property
    def dataSources(self):
        return

    @dataSources.setter
    def dataSources(self, value):
        logging.info("setting self.dataSources" + json.dumps(value))
        self._dataSources = value

if __name__ == '__main__':
    print()
    conf = {
        '/': {
            'tools.sessions.on': True,
            'tools.staticdir.root': os.path.dirname(os.path.realpath(__file__))
        },
        '/website': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': './website'
        }
    }

    cherrypy.quickstart(DekkoServer(), '/', conf)

使用此精确设置,不会观察到日志记录输出。

如果我在二传手中评论这一行

@dataSources.setter
def dataSources(self, value):
    # commenting this line allows log output as normal
    #logging.info("setting self.dataSources" + json.dumps(value))
    self._dataSources = value

但是,然后我按预期将日志输出保存在适当的文件中。

为什么会这样?我看不到装饰器有什么特别之处以防止记录。

0 个答案:

没有答案