Skip to content

Commit

Permalink
- Fix: Fixed the bug of Logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
byemaxx committed Dec 3, 2024
1 parent c20a653 commit 4f6b3b6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
6 changes: 5 additions & 1 deletion Docs/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
59 changes: 43 additions & 16 deletions metax/gui/main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion metax/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.119.2'
__version__ = '1.119.3'
API_version = '4'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit 4f6b3b6

Please sign in to comment.