MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / init

Method init

crates/opencode-util/src/logging.rs:323–353  ·  view source on GitHub ↗
(_level: Option<LogLevel>, log_dir: Option<PathBuf>, print: bool)

Source from the content-addressed store, hash-verified

321 }
322
323 pub fn init(_level: Option<LogLevel>, log_dir: Option<PathBuf>, print: bool) -> Option<PathBuf> {
324 if print {
325 return None;
326 }
327
328 let log_dir = log_dir.unwrap_or_else(|| PathBuf::from("."));
329 let timestamp = Local::now().format("%Y-%m-%dT%H%M%S").to_string();
330 let log_path = log_dir.join(format!("{}.log", timestamp));
331
332 if let Some(parent) = log_path.parent() {
333 let _ = std::fs::create_dir_all(parent);
334 }
335
336 let file = std::fs::OpenOptions::new()
337 .create(true)
338 .write(true)
339 .truncate(true)
340 .open(&log_path)
341 .ok();
342
343 if let Some(file) = file {
344 let writer: Arc<Mutex<Box<dyn Write + Send>>> = Arc::new(Mutex::new(Box::new(file)));
345 if let Ok(mut loggers) = LOGGERS.lock() {
346 for (_, cached) in loggers.iter_mut() {
347 cached.writer = Arc::clone(&writer);
348 }
349 }
350 }
351
352 Some(log_path)
353 }
354}
355
356pub fn init_tracing(_level: Option<&str>, log_dir: Option<PathBuf>, print: bool) -> Option<PathBuf> {

Callers 1

init_tracingFunction · 0.45

Calls 3

newFunction · 0.85
openMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected