Trying to improve logging a tad

This commit is contained in:
Mike 2019-08-05 03:36:23 -07:00
parent b979b6196f
commit b11d69c957
1 changed files with 13 additions and 8 deletions

View File

@ -81,11 +81,9 @@ class MikesBackup:
print(to_log) print(to_log)
# Append the log line to the log file # Append the log line to the log file
log_file_path = self.make_log_path() f = self.open_log_file()
if log_file_path: if f:
f = open(log_file_path, "a+")
f.write(to_log + "\n") f.write(to_log + "\n")
f.close()
# Recurse in order to print whatever o is outputting, if anything # Recurse in order to print whatever o is outputting, if anything
if o is not None: if o is not None:
@ -423,8 +421,8 @@ class MikesBackup:
# #
log_dir = self.__log_dir log_dir = self.__log_dir
if log_dir is None: if log_dir is None:
print("No log directory specified; Defaulting to current working directory") print("No log directory specified; Won't log")
log_dir = "." return None
return log_dir return log_dir
@ -433,6 +431,8 @@ class MikesBackup:
# Log dir # Log dir
log_dir = self.make_log_directory_path() log_dir = self.make_log_directory_path()
if not log_dir:
return None
# Path # Path
log_path = os.path.join(log_dir, self.get_datetime_for_filename() + ".log") log_path = os.path.join(log_dir, self.get_datetime_for_filename() + ".log")
@ -623,10 +623,8 @@ class MikesBackup:
def start_rsync_args(self): def start_rsync_args(self):
# #
self.ensure_local_directory(self.make_log_directory_path())
args = [ args = [
"rsync", "rsync",
"--log-file", self.make_log_path(),
"--archive", "--archive",
"--compress", "--compress",
"--progress", "--progress",
@ -638,6 +636,13 @@ class MikesBackup:
"--delete-excluded" "--delete-excluded"
] ]
log_dir = self.make_log_directory_path()
log_path = self.make_log_path()
if log_dir and log_path:
self.ensure_local_directory(log_dir)
args.append("--log-file")
args.append(log_path)
# #
for i in self.__source_dir_includes: for i in self.__source_dir_includes:
args.append("--include") args.append("--include")