Skip to content

Commit

Permalink
fixed logging issue in Client.file_exists method
Browse files Browse the repository at this point in the history
  • Loading branch information
charlottekostelic committed Aug 15, 2024
1 parent df3f220 commit b15b6d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 2 additions & 6 deletions file_retriever/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def get_file_permissions(data):
file_mtime=time[4:],
file_mode=permissions,
)
except ftplib.error_perm as e:
# remove logging?
logger.error(f"Unable to retrieve file data for {file_name}: {e}")
except ftplib.error_perm:
raise RetrieverFileError

def list_file_data(self, dir: str) -> List[FileInfo]:
Expand Down Expand Up @@ -432,9 +430,7 @@ def get_file_data(self, file_name: str, dir: str) -> FileInfo:
return FileInfo.from_stat_data(
data=self.connection.stat(file_name), file_name=file_name
)
except OSError as e:
# remove logging?
logger.error(f"Unable to retrieve file data for {file_name}: {e}")
except OSError:
raise RetrieverFileError

def list_file_data(self, dir: str) -> List[FileInfo]:
Expand Down
4 changes: 2 additions & 2 deletions file_retriever/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ def list_file_info(
time_delta = time_delta
if not remote_dir or remote_dir is None:
remote_dir = self.remote_dir
logger.debug(f"({self.name}) Listing all files in `{remote_dir}`")
logger.debug(f"({self.name}) Retrieving list of files in `{remote_dir}`")
files = self.session.list_file_data(dir=remote_dir)
if time_delta > datetime.timedelta(days=0):
logger.debug(
f"({self.name}) Filtering list for files created "
f"since {today - time_delta}"
f"since {datetime.datetime.strftime((today - time_delta), '%Y-%m-%d')}"
)
recent_files = [
i
Expand Down
15 changes: 14 additions & 1 deletion file_retriever/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@


def logger_config() -> dict:
"""Create and return dict for logger configuration"""
"""
Create and return dict for logger configuration.
INFO and DEBUG logs are recorded in methods of the `Client` class while
ERROR logs are primarily recorded in methods of the `_ftpClient` and
`_sftpClient` classes. The one exception to this is ERROR messages
logged by the `_ftpClient` and `_sftpClient` `get_file_data` methods.
These are logged as errors in the `Client` class in order avoid logging
errors when files are not found by the `Client.file_exists` method.
Returns:
dict: dictionary with logger configuration
"""
log_config_dict = {
"version": 1,
"formatters": {
Expand Down

0 comments on commit b15b6d1

Please sign in to comment.