Skip to content

Commit

Permalink
Merge pull request #10468 from clacroix12/fix-logging-statements
Browse files Browse the repository at this point in the history
Fix direct use of logging module
  • Loading branch information
petr-balogh authored Sep 12, 2024
2 parents 21d09d7 + e4bcbb2 commit 7c8abb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ocs_ci/templates/workloads/helper_scripts/file_creator_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import logging

logger = logging.getLogger(__name__)


def create_files(base_path, num_files):
try:
Expand All @@ -14,7 +16,7 @@ def create_files(base_path, num_files):
file_paths.append(file_path)
return file_paths
except Exception as e:
logging.error(f"Error during file creation: {str(e)}")
logger.error(f"Error during file creation: {str(e)}")
return []


Expand Down
11 changes: 6 additions & 5 deletions ocs_ci/templates/workloads/helper_scripts/meta_data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)


def log_metadata_operation(operation, file_path, from_metadata, to_metadata):
log_message = (
f"{operation} metadata for file {file_path}: {from_metadata} -> {to_metadata}"
)
logging.info(log_message)
logger.info(log_message)


def create_files(base_path, num_files):
Expand All @@ -35,7 +36,7 @@ def create_files(base_path, num_files):
file_paths.append(file_path)
return file_paths
except Exception as e:
logging.error(f"Error during file creation: {str(e)}")
logger.error(f"Error during file creation: {str(e)}")
return []


Expand All @@ -44,15 +45,15 @@ def get_extended_attribute(file_path, attr_name):
attr_value = os.getxattr(file_path, attr_name)
return attr_value.decode("utf-8")
except (OSError, IOError) as e:
logging.error(f"Error getting extended attribute: {str(e)}")
logger.error(f"Error getting extended attribute: {str(e)}")
return None


def set_extended_attribute(file_path, attr_name, attr_value):
try:
os.setxattr(file_path, attr_name, attr_value.encode("utf-8"))
except (OSError, IOError) as e:
logging.error(f"Error setting extended attribute: {str(e)}")
logger.error(f"Error setting extended attribute: {str(e)}")


def perform_metadata_operations(file_path):
Expand Down Expand Up @@ -100,7 +101,7 @@ def perform_metadata_operations(file_path):
fcntl.flock(lock_file, fcntl.LOCK_UN)

except Exception as e:
logging.error(f"Error during metadata operations: {str(e)}")
logger.error(f"Error during metadata operations: {str(e)}")


if __name__ == "__main__":
Expand Down

0 comments on commit 7c8abb5

Please sign in to comment.