22
33from __future__ import annotations
44
5+ import logging
56from pathlib import Path
67from typing import TYPE_CHECKING
78
1314if TYPE_CHECKING :
1415 from gitingest .schemas import IngestionQuery
1516
17+ logger = logging .getLogger (__name__ )
18+
1619
1720def ingest_query (query : IngestionQuery ) -> tuple [str , str , str ]:
1821 """Run the ingestion process for a parsed query.
@@ -111,7 +114,7 @@ def _process_node(node: FileSystemNode, query: IngestionQuery, stats: FileSystem
111114 _process_symlink (path = sub_path , parent_node = node , stats = stats , local_path = query .local_path )
112115 elif sub_path .is_file ():
113116 if sub_path .stat ().st_size > query .max_file_size :
114- print ( f "Skipping file { sub_path } : would exceed max file size limit" )
117+ logger . info ( "Skipping file %s : would exceed max file size limit" , sub_path )
115118 continue
116119 _process_file (path = sub_path , parent_node = node , stats = stats , local_path = query .local_path )
117120 elif sub_path .is_dir ():
@@ -133,7 +136,7 @@ def _process_node(node: FileSystemNode, query: IngestionQuery, stats: FileSystem
133136 node .file_count += child_directory_node .file_count
134137 node .dir_count += 1 + child_directory_node .dir_count
135138 else :
136- print ( f "Warning: { sub_path } is an unknown file type, skipping" )
139+ logger . warning ( "Warning: %s is an unknown file type, skipping" , sub_path )
137140
138141 node .sort_children ()
139142
@@ -186,12 +189,12 @@ def _process_file(path: Path, parent_node: FileSystemNode, stats: FileSystemStat
186189
187190 """
188191 if stats .total_files + 1 > MAX_FILES :
189- print ( f "Maximum file limit ({ MAX_FILES } ) reached" )
192+ logger . warning ( "Maximum file limit (%i ) reached" , MAX_FILES )
190193 return
191194
192195 file_size = path .stat ().st_size
193196 if stats .total_size + file_size > MAX_TOTAL_SIZE_BYTES :
194- print ( f "Skipping file { path } : would exceed total size limit" )
197+ logger . info ( "Skipping file %s : would exceed total size limit" , path )
195198 return
196199
197200 stats .total_files += 1
@@ -232,15 +235,15 @@ def limit_exceeded(stats: FileSystemStats, depth: int) -> bool:
232235
233236 """
234237 if depth > MAX_DIRECTORY_DEPTH :
235- print ( f "Maximum depth limit ({ MAX_DIRECTORY_DEPTH } ) reached" )
238+ logger . warning ( "Maximum depth limit (%i ) reached" , MAX_DIRECTORY_DEPTH )
236239 return True
237240
238241 if stats .total_files >= MAX_FILES :
239- print ( f "Maximum file limit ({ MAX_FILES } ) reached" )
242+ logger . warning ( "Maximum file limit (%i ) reached" , MAX_FILES )
240243 return True # TODO: end recursion
241244
242245 if stats .total_size >= MAX_TOTAL_SIZE_BYTES :
243- print ( f "Maxumum total size limit ({ MAX_TOTAL_SIZE_BYTES / 1024 / 1024 :.1f } MB) reached" )
246+ logger . warning ( "Maxumum total size limit (%.1fMB) reached" , MAX_TOTAL_SIZE_BYTES / 1024 / 1024 )
244247 return True # TODO: end recursion
245248
246249 return False
0 commit comments