From b11d69c957b2cc0c07e48c92cd04d582b0ed9879 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 5 Aug 2019 03:36:23 -0700 Subject: [PATCH] Trying to improve logging a tad --- mikes-backup | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mikes-backup b/mikes-backup index 0f0acf0..e46dc61 100755 --- a/mikes-backup +++ b/mikes-backup @@ -81,11 +81,9 @@ class MikesBackup: print(to_log) # Append the log line to the log file - log_file_path = self.make_log_path() - if log_file_path: - f = open(log_file_path, "a+") + f = self.open_log_file() + if f: f.write(to_log + "\n") - f.close() # Recurse in order to print whatever o is outputting, if anything if o is not None: @@ -423,8 +421,8 @@ class MikesBackup: # log_dir = self.__log_dir if log_dir is None: - print("No log directory specified; Defaulting to current working directory") - log_dir = "." + print("No log directory specified; Won't log") + return None return log_dir @@ -433,6 +431,8 @@ class MikesBackup: # Log dir log_dir = self.make_log_directory_path() + if not log_dir: + return None # Path log_path = os.path.join(log_dir, self.get_datetime_for_filename() + ".log") @@ -623,10 +623,8 @@ class MikesBackup: def start_rsync_args(self): # - self.ensure_local_directory(self.make_log_directory_path()) args = [ "rsync", - "--log-file", self.make_log_path(), "--archive", "--compress", "--progress", @@ -638,6 +636,13 @@ class MikesBackup: "--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: args.append("--include")