From e76b79090d97c04510dff9c9c6cb7480b32cfea8 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Thu, 3 Oct 2024 19:51:12 +0200 Subject: [PATCH] Ticket #804: Move log Also emit less logs on the console by default. Log file still contains the full output. --- gitlib/gitlib.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/gitlib/gitlib.py b/gitlib/gitlib.py index 2fb9470..4630192 100755 --- a/gitlib/gitlib.py +++ b/gitlib/gitlib.py @@ -1423,7 +1423,7 @@ class OpengnsysGitLibrary: add_files = add_files_new - self.logger.debug("Adding %d files" % len(add_files)) + self.logger.info("Adding %d files" % len(add_files)) with OperationTimer(self, "add all files"): #subprocess.run(["git", "add"] + add_files, check=True, cwd=path) repo.index.add(items = add_files, force=True ) @@ -1441,7 +1441,7 @@ class OpengnsysGitLibrary: subprocess.run(["git", "add"] + untracked_list, check=True, cwd=path) - self.logger.debug("Committing") + self.logger.info("Committing") repo.index.commit("Initial commit") # Restaurar cosas modificadas para git @@ -1466,7 +1466,7 @@ class OpengnsysGitLibrary: # repo.create_head # repo.heads.master.set_tracking_branch(origin.refs.master) - self.logger.debug("Uploading to ogrepository") + self.logger.info("Uploading to ogrepository") repo.git.push("--set-upstream", "origin", repo.head.ref, "--force") # force = True) def cloneRepo(self, repo_name, destination, boot_device): @@ -1597,13 +1597,18 @@ if __name__ == '__main__': # esto arregla las tildes y las eñes sys.stdout.reconfigure(encoding='utf-8') + opengnsys_log_dir = "/opt/opengnsys/log" + logger = logging.getLogger(__package__) logger.setLevel(logging.DEBUG) streamLog = logging.StreamHandler() - streamLog.setLevel(logging.DEBUG) + streamLog.setLevel(logging.INFO) - fileLog = logging.FileHandler("gitlib.log") + if not os.path.exists(opengnsys_log_dir): + os.mkdir(opengnsys_log_dir) + + fileLog = logging.FileHandler(f"{opengnsys_log_dir}/gitlib.log") fileLog.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)24s - [%(levelname)5s] - %(message)s') @@ -1637,12 +1642,15 @@ if __name__ == '__main__': parser.add_argument("--test-restore-metadata-destructive", type=str, metavar="DIR", help="Test metadata restoration, destructive parts only") parser.add_argument("--test-clone-metadata", type=str, metavar="REPO", help="Test metadata cloning") + parser.add_argument("-v", "--verbose", action="store_true", help = "Verbose console output") args = parser.parse_args() + if args.verbose: + streamLog.setLevel(logging.DEBUG) - logger.debug("Inicio") + logger.debug("Starting") ntfs_impl = NTFSImplementation.Kernel