Skip to content

Commit 9adee40

Browse files
committed
Refactor logging in GenerateCommand and FileItem for improved clarity and structure
1 parent 23b2437 commit 9adee40

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

struct_module/commands/generate.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def __init__(self, parser):
2222
parser.set_defaults(func=self.execute)
2323

2424
def execute(self, args):
25-
self.logger.info(f"Generating structure at {args.base_path} with config {args.structure_definition}")
25+
self.logger.info(f"Generating structure")
26+
self.logger.info(f" Structure definition: {args.structure_definition}")
27+
self.logger.info(f" Base path: {args.base_path}")
2628

2729
if args.backup and not os.path.exists(args.backup):
2830
os.makedirs(args.backup)
@@ -96,11 +98,14 @@ def _create_structure(self, args):
9698
self.logger.info(f"[DRY RUN] Would create folder: {folder_path}")
9799
continue
98100
os.makedirs(folder_path, exist_ok=True)
99-
self.logger.info(f"Created folder: {folder_path}")
101+
self.logger.info(f"Created folder")
102+
self.logger.info(f" Folder: {folder_path}")
100103

101104
# check if content has struct value
102105
if 'struct' in content:
103-
self.logger.info(f"Generating structure in folder: {folder} with struct {content['struct']}")
106+
self.logger.info(f"Generating structure")
107+
self.logger.info(f" Folder: {folder}")
108+
self.logger.info(f" Struct: {content['struct']}")
104109

105110
# get vars from with param. this will be a dict of key value pairs
106111
merged_vars = ""

struct_module/file_item.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over
121121
file_path = os.path.join(base_path, self.name)
122122

123123
if self.skip:
124-
self.logger.info(f"Skipping file creation: {file_path}")
124+
self.logger.info(f"Skipping file creation")
125+
self.logger.info(f" File path: {file_path}")
125126
return
126127

127128
if dry_run:
@@ -141,7 +142,7 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over
141142
return
142143
elif file_strategy == 'append':
143144
with open(file_path, 'a') as f:
144-
f.write(self.content)
145+
f.write(f"{self.content}\n")
145146
self.logger.info(f"Appended to existing file: {file_path}")
146147
return
147148
elif file_strategy == 'rename':
@@ -150,9 +151,13 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over
150151
self.logger.info(f"Renamed existing file: {file_path} to {new_name}")
151152

152153
with open(file_path, 'w') as f:
153-
f.write(self.content)
154-
self.logger.debug(f"Created file: {file_path} with content: \n\n{self.content}")
154+
f.write(f"{self.content}\n")
155+
self.logger.debug(f"Created file with content")
156+
self.logger.debug(f" File path: {file_path}")
157+
self.logger.debug(f" Content: \n\n{self.content}")
155158

156159
if self.permissions:
157160
os.chmod(file_path, int(self.permissions, 8))
158-
self.logger.info(f"Set permissions {self.permissions} for file: {file_path}")
161+
self.logger.info(f"Set permissions to file")
162+
self.logger.info(f" File path: {file_path}")
163+
self.logger.info(f" Permissions: {self.permissions}")

0 commit comments

Comments
 (0)