логи получше
This commit is contained in:
parent
682e2a404a
commit
cbcf468009
@ -34,20 +34,14 @@ class MyLog:
|
|||||||
self.logger = logging.getLogger("main")
|
self.logger = logging.getLogger("main")
|
||||||
self.logger.setLevel(logging.DEBUG)
|
self.logger.setLevel(logging.DEBUG)
|
||||||
# Console logging
|
# Console logging
|
||||||
self.console = self.get_console_handler()
|
|
||||||
self.console.setFormatter(CustomFormatter())
|
|
||||||
self.logger.addHandler(self.console)
|
|
||||||
|
|
||||||
self.logger.addHandler(self.get_file_handler())
|
|
||||||
self.logger.propagate = False
|
|
||||||
|
|
||||||
def get_console_handler(self):
|
|
||||||
console_handler = logging.StreamHandler(sys.stdout)
|
console_handler = logging.StreamHandler(sys.stdout)
|
||||||
console_handler.setFormatter(log_format)
|
console_handler.setFormatter(log_format)
|
||||||
return console_handler
|
|
||||||
|
|
||||||
def get_file_handler(self):
|
console = console_handler
|
||||||
|
console.setFormatter(CustomFormatter())
|
||||||
|
self.logger.addHandler(console)
|
||||||
|
|
||||||
file_handler = TimedRotatingFileHandler(log_file, when='midnight')
|
file_handler = TimedRotatingFileHandler(log_file, when='midnight')
|
||||||
file_handler.setFormatter(log_format)
|
file_handler.setFormatter(log_format)
|
||||||
return file_handler
|
self.logger.addHandler(file_handler)
|
||||||
|
self.logger.propagate = False
|
||||||
|
@ -134,4 +134,4 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
check_alive()
|
check_alive()
|
||||||
time.sleep(config_python.check_period)
|
time.sleep(config_python.check_period)
|
||||||
|
Loading…
Reference in New Issue
Block a user