diff --git a/Docs/ChangeLog.md b/Docs/ChangeLog.md index 840551a..29daf0a 100644 --- a/Docs/ChangeLog.md +++ b/Docs/ChangeLog.md @@ -1,9 +1,13 @@ +# Version: 1.119.3 +## Date: 2024-12-3 +### Changes: +- Fix: Fixed the bug of Logger. + # Version: 1.119.2 ## Date: 2024-12-3 ### Changes: - Change: Change the layout of selection group or sample group in the basic plot part to make the layout more clear. - # Version: 1.119.1 ## Date: 2024-11-29 ### Changes: diff --git a/metax/gui/main_gui.py b/metax/gui/main_gui.py index 8b4c8a3..27af24d 100644 --- a/metax/gui/main_gui.py +++ b/metax/gui/main_gui.py @@ -5934,36 +5934,63 @@ def set_lineEdit_db_save_path(self): ############### Class LoggerManager Begin ############### class LoggerManager: - def __init__(self): - self.setup_logging() + def __init__(self, log_level=logging.DEBUG): + self.setup_logging(log_level) self.write_log(f'------------------------------ MetaX Started Version {__version__} ------------------------------', 'i') - - def setup_logging(self): + + def setup_logging(self, log_level=logging.DEBUG): """ - Configure logging settings. + Configure logging settings for LoggerManager. """ + self.logger = logging.getLogger('MetaXLogger') + self.logger.setLevel(log_level) + # Disable matplotlib logging for warnings matplotlib_logger = logging.getLogger('matplotlib') matplotlib_logger.setLevel(logging.WARNING) - + + # Create log directory if not exists home_path = os.path.expanduser("~") metax_path = os.path.join(home_path, 'MetaX') - if not os.path.exists(metax_path): - os.makedirs(metax_path) + try: + if not os.path.exists(metax_path): + os.makedirs(metax_path) + except Exception as e: + print(f"Error creating log directory: {metax_path}. {e}") + metax_path = home_path # Fallback to home directory + log_path = os.path.join(metax_path, 'MetaX.log') + + # Define formatter and handlers log_format = '%(asctime)s - %(levelname)s - %(message)s' - logging.basicConfig(filename=log_path, level=logging.DEBUG, format=log_format) + formatter = logging.Formatter(log_format) + + # File handler + file_handler = logging.FileHandler(log_path) + file_handler.setFormatter(formatter) + self.logger.addHandler(file_handler) + + # Stream handler (optional, for console logging) + stream_handler = logging.StreamHandler() + stream_handler.setFormatter(formatter) + self.logger.addHandler(stream_handler) - def write_log(self, msg:str, level:str='i'): + def write_log(self, msg: str, level: str = 'i'): + """ + Write a log message with the specified logging level. + Args: + msg (str): The log message. + level (str): The log level ('d', 'i', 'w', 'e', 'c'). + """ level_dict = { - 'd': logging.debug, - 'i': logging.info, - 'w': logging.warning, - 'e': logging.error, - 'c': logging.critical + 'd': self.logger.debug, + 'i': self.logger.info, + 'w': self.logger.warning, + 'e': self.logger.error, + 'c': self.logger.critical, } msg = msg.replace('\n', ' ').replace('\r', '') - log_func = level_dict.get(level, logging.info) + log_func = level_dict.get(level, self.logger.info) log_func(msg) diff --git a/metax/utils/version.py b/metax/utils/version.py index 40370b8..35786cc 100644 --- a/metax/utils/version.py +++ b/metax/utils/version.py @@ -1,2 +1,2 @@ -__version__ = '1.119.2' +__version__ = '1.119.3' API_version = '4' \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d4b2897..5fdc7df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "MetaXTools" -version = "1.119.2" +version = "1.119.3" description = "MetaXTools is a novel tool for linking peptide sequences with taxonomic and functional information in Metaproteomics." readme = "README_PyPi.md" license = { text = "NorthOmics" }