MCPcopy Index your code
hub / github.com/Codeplain-ai/codeplain / setup_logging

Function setup_logging

plain2code.py:83–140  ·  view source on GitHub ↗
(
    args,
    event_bus: EventBus,
    run_state: RunState,
    log_to_file: bool,
    log_file_name: str,
    plain_file_path: Optional[str],
    headless: bool = False,
)

Source from the content-addressed store, hash-verified

81
82
83def setup_logging(
84 args,
85 event_bus: EventBus,
86 run_state: RunState,
87 log_to_file: bool,
88 log_file_name: str,
89 plain_file_path: Optional[str],
90 headless: bool = False,
91):
92 default_level = logging.DEBUG if args.verbose else logging.INFO
93
94 logging.getLogger().setLevel(default_level)
95 logging.getLogger(LOGGER_NAME).setLevel(default_level)
96 logging.getLogger("git").setLevel(logging.WARNING)
97 logging.getLogger("transitions").setLevel(logging.ERROR)
98 logging.getLogger("transitions.extensions.diagrams").setLevel(logging.ERROR)
99
100 log_file_path = get_log_file_path(plain_file_path, log_file_name)
101
102 # Try to load logging configuration from YAML file (takes precedence over --verbose)
103 config_loaded = False
104 if args.logging_config_path and os.path.exists(args.logging_config_path):
105 try:
106 with open(args.logging_config_path, "r") as f:
107 config = yaml.safe_load(f)
108 logging.config.dictConfig(config)
109 console.info(f"Loaded logging configuration from {args.logging_config_path}")
110 config_loaded = True
111 except Exception as e:
112 console.warning(f"Failed to load logging configuration from {args.logging_config_path}: {str(e)}")
113
114 root_logger = logging.getLogger(LOGGER_NAME)
115 configured_log_level = root_logger.level if config_loaded else default_level
116 root_logger.setLevel(logging.DEBUG) # Capture all logs; handlers will filter levels as needed
117
118 formatter = IndentedFormatter("%(levelname)s:%(name)s:%(message)s")
119 file_formatter = ElapsedTimeFormatter(run_state)
120
121 if not headless:
122 handler = LoggingHandler(event_bus, run_state)
123 handler.setFormatter(formatter)
124 root_logger.addHandler(handler)
125
126 if log_to_file and log_file_path:
127 try:
128 file_handler = logging.FileHandler(log_file_path, mode="w", encoding="utf-8")
129 file_handler.setFormatter(file_formatter)
130 file_handler.setLevel(configured_log_level)
131 root_logger.addHandler(file_handler)
132 except Exception as e:
133 console.warning(f"Failed to setup file logging to {log_file_path}: {str(e)}")
134 else:
135 crash_handler = CrashLogHandler()
136 crash_handler.setFormatter(file_formatter)
137 crash_handler.setLevel(configured_log_level)
138 root_logger.addHandler(crash_handler)
139
140 return logging.getLevelName(configured_log_level)

Callers 1

mainFunction · 0.85

Calls 7

get_log_file_pathFunction · 0.90
IndentedFormatterClass · 0.90
LoggingHandlerClass · 0.90
CrashLogHandlerClass · 0.90
infoMethod · 0.80
warningMethod · 0.80

Tested by

no test coverage detected