From 890c355645019908a0a890bef03d27046a2524e5 Mon Sep 17 00:00:00 2001 From: Kenneth Belitzky Date: Thu, 5 Jun 2025 01:12:24 +0000 Subject: [PATCH] Enhance logging messages with emojis for better visibility and user experience --- struct_module/commands/generate.py | 12 +++++++++--- struct_module/commands/info.py | 2 +- struct_module/file_item.py | 22 ++++++++++------------ struct_module/logging_config.py | 2 +- struct_module/template_renderer.py | 2 +- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/struct_module/commands/generate.py b/struct_module/commands/generate.py index aa8cd4f..9572fcc 100644 --- a/struct_module/commands/generate.py +++ b/struct_module/commands/generate.py @@ -56,7 +56,7 @@ def _create_structure(self, args): file_path = os.path.join(contribs_path, f"{args.structure_definition}.yaml") if not os.path.exists(file_path): - self.logger.error(f"File not found: {file_path}") + self.logger.error(f"❗ File not found: {file_path}") return with open(file_path, 'r') as f: @@ -94,7 +94,7 @@ def _create_structure(self, args): file_path_to_create = os.path.join(args.base_path, name) existing_content = None if os.path.exists(file_path_to_create): - self.logger.info(f"File already exists: {file_path_to_create}") + self.logger.warning(f"⚠️ File already exists: {file_path_to_create}") with open(file_path_to_create, 'r') as existing_file: existing_content = existing_file.read() @@ -125,7 +125,13 @@ def _create_structure(self, args): if 'struct' in content: self.logger.info(f"Generating structure") self.logger.info(f" Folder: {folder}") - self.logger.info(f" Struct: {content['struct']}") + self.logger.info(f" Struct:") + if isinstance(content['struct'], list): + # iterate over the list of structures + for struct in content['struct']: + self.logger.info(f" - {struct}") + if isinstance(content['struct'], str): + self.logger.info(f" - {content['struct']}") # get vars from with param. this will be a dict of key value pairs merged_vars = "" diff --git a/struct_module/commands/info.py b/struct_module/commands/info.py index b060d10..318d6ea 100644 --- a/struct_module/commands/info.py +++ b/struct_module/commands/info.py @@ -29,7 +29,7 @@ def _get_info(self, args): file_path = os.path.join(args.structures_path, f"{args.structure_definition}.yaml") # show error if file is not found if not os.path.exists(file_path): - self.logger.error(f"File not found: {file_path}") + self.logger.error(f"❗ File not found: {file_path}") return with open(file_path, 'r') as f: config = yaml.safe_load(f) diff --git a/struct_module/file_item.py b/struct_module/file_item.py index a8ede99..6b4c2ce 100644 --- a/struct_module/file_item.py +++ b/struct_module/file_item.py @@ -101,7 +101,7 @@ def fetch_content(self): self.content = self.content_fetcher.fetch_content(self.content_location) self.logger.debug(f"Fetched content: {self.content}") except Exception as e: - self.logger.error(f"Failed to fetch content from {self.content_location}: {e}") + self.logger.error(f"❗ Failed to fetch content from {self.content_location}: {e}") def _merge_default_template_vars(self, template_vars): default_vars = { @@ -125,8 +125,7 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over file_path = os.path.join(base_path, self.name) if self.skip: - self.logger.info(f"Skipping file creation") - self.logger.info(f" File path: {file_path}") + self.logger.info(f"skip is set to true. skipping creation.") return if dry_run: @@ -134,8 +133,7 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over return if self.skip_if_exists and os.path.exists(file_path): - self.logger.info(f"Skipping file creation as file exists") - self.logger.info(f" File path: {file_path}") + self.logger.info(f" skip_if_exists is set to true and file already exists. skipping creation.") return # Create the directory if it does not exist @@ -152,7 +150,7 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over elif file_strategy == 'append': with open(file_path, 'a') as f: f.write(f"{self.content}\n") - self.logger.info(f"Appended to existing file: {file_path}") + self.logger.info(f"✅ Appended to existing file: {file_path}") return elif file_strategy == 'rename': new_name = f"{file_path}.{int(time.time())}" @@ -161,12 +159,12 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over with open(file_path, 'w') as f: f.write(f"{self.content}\n") - self.logger.debug(f"Created file with content") - self.logger.debug(f" File path: {file_path}") - self.logger.debug(f" Content: \n\n{self.content}") + self.logger.info(f"✅ Created file with content") + self.logger.info(f" File path: {file_path}") + self.logger.debug(f" Content: \n\n{self.content}") if self.permissions: os.chmod(file_path, int(self.permissions, 8)) - self.logger.info(f"Set permissions to file") - self.logger.info(f" File path: {file_path}") - self.logger.info(f" Permissions: {self.permissions}") + self.logger.info(f"🔐 Set permissions to file") + self.logger.info(f" File path: {file_path}") + self.logger.info(f" Permissions: {self.permissions}") diff --git a/struct_module/logging_config.py b/struct_module/logging_config.py index 7e2cbb0..8d0fcce 100644 --- a/struct_module/logging_config.py +++ b/struct_module/logging_config.py @@ -6,7 +6,7 @@ def configure_logging(level=logging.INFO, log_file=None): """Configure logging with colorlog.""" handler = colorlog.StreamHandler() - line_format = "%(log_color)s[%(levelname)s] >> %(message)s" + line_format = "%(log_color)s%(message)s" if level == logging.DEBUG: line_format = "%(log_color)s[%(asctime)s][%(levelname)s][%(filename)s:%(lineno)d] >> %(message)s" diff --git a/struct_module/template_renderer.py b/struct_module/template_renderer.py index 6495cba..de5d45c 100644 --- a/struct_module/template_renderer.py +++ b/struct_module/template_renderer.py @@ -85,7 +85,7 @@ def prompt_for_missing_vars(self, content, vars): if self.non_interactive: user_input = default if default else "NEEDS_TO_BE_SET" else: - user_input = input(f"Enter value for {var} [{default}]: ") or default + user_input = input(f"❓ Enter value for {var} [{default}]: ") or default self.input_store.set_value(var, user_input) vars[var] = user_input self.input_store.save()