From f84aea58f7f716ed6088c54b525d71282d407164 Mon Sep 17 00:00:00 2001 From: Federico Campoli Date: Sat, 18 Nov 2017 10:26:52 +0000 Subject: [PATCH] improve log line formatting. add separate logs per source --- CHANGELOG.rst | 3 ++- pg_chameleon/lib/global_lib.py | 14 ++++++++++---- pg_chameleon/lib/pg_lib.py | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 62c51a60..8dd331b3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,7 +20,8 @@ changelog * add not functional class pgsql_source for source type pgsql * allow ``type_override`` to be empty * add show_status command for displaying the log error entries - +* add separate logs for per source +* change log line formatting inspired by the super clean look in pgbackrest (thanks you guys) 2.0-alpha1 11 November 2017 ............................. diff --git a/pg_chameleon/lib/global_lib.py b/pg_chameleon/lib/global_lib.py index 32b8b77c..524c13fc 100644 --- a/pg_chameleon/lib/global_lib.py +++ b/pg_chameleon/lib/global_lib.py @@ -421,6 +421,7 @@ def start_replica(self): The method starts a new replica process. Is compulsory to specify a source name when running this method. """ + self.logger = self.__init_logger() replica_pid = os.path.expanduser('%s/%s.pid' % (self.config["pid_dir"],self.args.source)) if self.args.source == "*": @@ -601,17 +602,22 @@ def __init_logger(self): log_level = self.config["log_level"] log_dest = self.config["log_dest"] log_days_keep = self.config["log_days_keep"] - log_name = self.args.config + config_name = self.args.config + source_name = self.args.source debug_mode = self.args.debug - + if source_name == '*': + log_name = "%s_general" % (config_name) + else: + log_name = "%s_%s" % (config_name, source_name) + log_file = os.path.expanduser('%s/%s.log' % (log_dir,log_name)) logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) logger.propagate = False if debug_mode: - str_format = "[%(levelname)s] - (%(processName)s): %(asctime)s: %(filename)s (%(lineno)s): %(message)s" + str_format = "%(asctime)s %(processName)s %(levelname)s %(filename)s (%(lineno)s): %(message)s" else: - str_format = "[%(levelname)s] - %(processName)s: %(asctime)s: : %(message)s" + str_format = "%(asctime)s %(processName)s %(levelname)s: %(message)s" formatter = logging.Formatter(str_format, "%Y-%m-%d %H:%M:%S") if log_dest=='stdout' or debug_mode: diff --git a/pg_chameleon/lib/pg_lib.py b/pg_chameleon/lib/pg_lib.py index 48b9905f..105d4386 100644 --- a/pg_chameleon/lib/pg_lib.py +++ b/pg_chameleon/lib/pg_lib.py @@ -1814,7 +1814,7 @@ def clean_not_processed_batches(self): sch_chameleon.t_replica_batch WHERE i_id_source=%s - and not b_processed + AND NOT b_processed ) ; """