refactor(logging): Add optional logging support throughout codebase
Add centralized logging utility and optional logger parameters to all core functions for better observability and debugging capabilities. New modules: - utils/logging.py: Centralized logger configuration with console and optional file handlers Enhanced features: - Added optional logger parameter to all extractor_core functions - Added logger support to extractor, excel_converter, and auth modules - Functions remain silent when logger=None (backward compatible) - Improved environment variable validation in test files Documentation: - Added discrete_material_plan_extractor_core.md with complete API reference and usage patterns Benefits: - Consistent logging format across all components - Optional debug output for troubleshooting - No breaking changes - fully backward compatible - Better error messages and validation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,10 @@ from dotenv import load_dotenv
|
||||
load_dotenv(PROJECT_ROOT / ".env")
|
||||
|
||||
# Configure browser path
|
||||
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = os.getenv("PLAYWRIGHT_BROWSERS_PATH")
|
||||
browser_path = os.getenv("PLAYWRIGHT_BROWSERS_PATH")
|
||||
if not browser_path:
|
||||
raise ValueError("PLAYWRIGHT_BROWSERS_PATH environment variable is required")
|
||||
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = browser_path
|
||||
|
||||
print("=" * 60)
|
||||
print("Testing Yonyou BIP Login and Logout")
|
||||
@@ -38,15 +41,24 @@ if not base_url:
|
||||
url = f"{base_url.rstrip('/')}/yonbip/resources/uap/rbac/login/main/index.html"
|
||||
|
||||
try:
|
||||
# Get required environment variables
|
||||
username = os.getenv('ERP_USERNAME')
|
||||
password = os.getenv('ERP_PASSWORD')
|
||||
headless = os.getenv('ERP_HEADLESS', 'false').lower() in ('true', '1', 'yes')
|
||||
ignore_https_errors = os.getenv('ERP_IGNORE_HTTPS_ERRORS', 'true').lower() in ('true', '1', 'yes')
|
||||
|
||||
if not username or not password:
|
||||
raise ValueError("ERP_USERNAME and ERP_PASSWORD environment variables are required")
|
||||
|
||||
with sync_playwright() as p:
|
||||
print("\n[1/5] Starting browser...")
|
||||
browser, context, page, main_frame = login(
|
||||
playwright=p,
|
||||
username=os.getenv('ERP_USERNAME'),
|
||||
password=os.getenv('ERP_PASSWORD'),
|
||||
username=username,
|
||||
password=password,
|
||||
url=url,
|
||||
headless=os.getenv('ERP_HEADLESS', 'false').lower() in ('true', '1', 'yes'),
|
||||
ignore_https_errors=os.getenv('ERP_IGNORE_HTTPS_ERRORS', 'true').lower() in ('true', '1', 'yes'),
|
||||
headless=headless,
|
||||
ignore_https_errors=ignore_https_errors,
|
||||
verbose=True
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user