]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Creating additional error log
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Jan 2021 14:14:53 +0000 (15:14 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 6 Jan 2021 14:14:53 +0000 (15:14 +0100)
lib/ldap_migration/__init__.py

index 9221628860606956725a8064e219aa5c6293e396..a30956f70edf65e203c9b6cb3d01a5a23f4d9a7d 100644 (file)
@@ -46,7 +46,7 @@ from fb_tools.collections import CIStringSet, CIDict
 
 from .config import LDAPMigrationConfiguration
 
-__version__ = '0.9.1'
+__version__ = '0.9.2'
 
 LOG = logging.getLogger(__name__)
 CFG_BASENAME = 'ldap-migration.ini'
@@ -199,6 +199,7 @@ class LDAPMigrationApplication(BaseApplication):
         self.structural_dns_file = None
         self.migrated_file = None
         self.general_logfile = None
+        self.error_logfile = None
         self.lap = 0
         self.total_count = 0
 
@@ -354,11 +355,11 @@ class LDAPMigrationApplication(BaseApplication):
         return formatter
 
     # -------------------------------------------------------------------------
-    def _get_logfile_formatter(self):
+    def _get_logfile_formatter(self, full=False):
 
         format_str = '[%(asctime)s]: '
         format_str += self.appname + ': '
-        if self.verbose > 1:
+        if self.verbose > 1 or full:
             format_str += '%(name)s(%(lineno)d) %(funcName)s() '
         else:
             format_str += '%(name)s '
@@ -415,6 +416,14 @@ class LDAPMigrationApplication(BaseApplication):
         lh_file.setFormatter(lf_formatter)
         root_logger.addHandler(lh_file)
 
+        # creating a log handler for errors
+        lf_formatter_err = self._get_logfile_formatter(full=True)
+        lh_errorlog = logging.FileHandler(
+                str(self.error_logfile), mode='a', encoding='utf-8', delay=True)
+        lh_errorlog.setLevel(logging.WARNING)
+        lh_errorlog.setFormatter(lf_formatter_err)
+        root_logger.addHandler(lh_errorlog)
+
         return
 
     # -------------------------------------------------------------------------
@@ -441,6 +450,7 @@ class LDAPMigrationApplication(BaseApplication):
         self.structural_dns_file = self.log_dir / 'structural-dns.{}.txt'.format(file_timestamp)
         self.migrated_file = self.log_dir / 'migrated-entries.{}.txt'.format(file_timestamp)
         self.general_logfile = self.log_dir / 'migration.{}.log'.format(file_timestamp)
+        self.error_logfile = self.log_dir / 'error.{}.log'.format(file_timestamp)
 
         self.init_logging()