فهرست منبع

core/log: do not attach multiple handlers to the same logger

logging.getLogger when given the same name twice, will return the same
object. Do not attach handler there every time, it will really open new
file, leading to multiplicated log entries and depleting file
descriptors.

QubesOS/qubes-issues#1697
Marek Marczykowski-Górecki 8 سال پیش
والد
کامیت
539a46ca9a
1فایلهای تغییر یافته به همراه2 افزوده شده و 0 حذف شده
  1. 2 0
      qubes/log.py

+ 2 - 0
qubes/log.py

@@ -125,6 +125,8 @@ def get_vm_logger(vmname):
     '''
 
     logger = logging.getLogger('vm.' + vmname)
+    if logger.handlers:
+        return logger
     handler = logging.FileHandler(
         os.path.join(LOGPATH, 'vm-{}.log'.format(vmname)))
     handler.setFormatter(formatter_log)