Skip to content

Commit

Permalink
improve log line formatting. add separate logs per source
Browse files Browse the repository at this point in the history
  • Loading branch information
the4thdoctor committed Nov 18, 2017
1 parent 95b590a commit f84aea5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
.............................
Expand Down
14 changes: 10 additions & 4 deletions pg_chameleon/lib/global_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "*":
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pg_chameleon/lib/pg_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
;
"""
Expand Down

0 comments on commit f84aea5

Please sign in to comment.