#!/usr/bin/env python3 """ Remove m_logger member variables and adapt LOG macros to use INGLogger::getLogger() directly. """ import os import re import sys def process_file(filepath): """Process a single file to remove m_logger and adapt macros.""" with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() original_content = content changes_made = False # Check if file uses LOGGER_T m_logger or NGL::INGLLogger &m_logger if 'LOGGER_T m_logger' not in content and 'NGL::INGLLogger' not in content and 'm_logger(' not in content: return False # Step 1: Remove "LOGGER_T m_logger;" and "NGL::INGLLogger &m_logger;" from class declarations # Handle lines with optional comments after the member declaration content = re.sub(r'[ \t]*LOGGER_T\s+m_logger;[^\n]*\n', '\n', content) content = re.sub(r'[ \t]*NGL::INGLLogger\s*&\s*m_logger;[^\n]*\n', '\n', content) content = re.sub(r'[ \t]*NGL::INGLLogger\s+m_logger;[^\n]*\n', '\n', content) # Step 2: Remove ", m_logger(getLogger(...))" from constructor initializer lists content = re.sub(r'\s*,\s*m_logger\s*\(\s*getLogger\s*\(\s*"[^"]*"\s*\)\s*\)', '', content) # Step 3: Replace LOG macros that use m_logger with direct getLogger() call # TRACE_LOG(m_logger) -> TRACE_LOG() content = re.sub(r'TRACE_LOG\s*\(\s*m_logger\s*\)', 'TRACE_LOG()', content) content = re.sub(r'DEBUG_LOG\s*\(\s*m_logger\s*\)', 'DEBUG_LOG()', content) content = re.sub(r'INFO_LOG\s*\(\s*m_logger\s*\)', 'INFO_LOG()', content) content = re.sub(r'WARNING_LOG\s*\(\s*m_logger\s*\)', 'WARNING_LOG()', content) content = re.sub(r'ERROR_LOG\s*\(\s*m_logger\s*\)', 'ERROR_LOG()', content) content = re.sub(r'LOGFUNCTION', 'Q_FUNC_INFO', content) if content != original_content: with open(filepath, 'w', encoding='utf-8') as f: f.write(content) return True return False def main(): if len(sys.argv) < 2: print("Usage: remove_logger_members.py ") sys.exit(1) base_dir = sys.argv[1] processed = 0 changed = 0 for root, dirs, files in os.walk(base_dir): # Skip build directories if 'build' in root or '.git' in root: continue for file in files: if file.endswith(('.h', '.cpp', '.hpp', '.cc')): filepath = os.path.join(root, file) processed += 1 if process_file(filepath): changed += 1 print(f"Modified: {filepath}") print(f"\nProcessed {processed} files, modified {changed} files") if __name__ == '__main__': main()