[2ff88f42] refactor(connector-superoffice): finalize production readiness cleanup
- Integrated centralized logging system in all modules. - Extracted all IDs and ProgIds into a separate . - Refactored and for cleaner dependency management. - Included updated discovery and inspection utilities. - Verified end-to-end workflow stability.
This commit is contained in:
42
connector-superoffice/logging_config.py
Normal file
42
connector-superoffice/logging_config.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
import os
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
def setup_logging(name="connector", log_level=logging.INFO):
|
||||
"""
|
||||
Sets up a robust logging configuration.
|
||||
Logs to console and to a rotating file.
|
||||
"""
|
||||
# Create logs directory if it doesn't exist
|
||||
log_dir = "logs"
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir)
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(log_level)
|
||||
|
||||
# Avoid duplicate handlers if setup is called multiple times
|
||||
if logger.handlers:
|
||||
return logger
|
||||
|
||||
# Formatter
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
|
||||
# Console Handler
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(formatter)
|
||||
logger.addHandler(console_handler)
|
||||
|
||||
# File Handler (Rotating: 5MB size, keep last 3 files)
|
||||
file_handler = RotatingFileHandler(
|
||||
os.path.join(log_dir, f"{name}.log"),
|
||||
maxBytes=5*1024*1024,
|
||||
backupCount=3
|
||||
)
|
||||
file_handler.setFormatter(formatter)
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
return logger
|
||||
Reference in New Issue
Block a user