MCPcopy Index your code
hub / github.com/idank/explainshell / _attach_run_log

Function _attach_run_log

explainshell/manager.py:454–472  ·  view source on GitHub ↗

Create a timestamped run dir and attach a file handler. Returns the run dir.

(log_level_str: str)

Source from the content-addressed store, hash-verified

452
453
454def _attach_run_log(log_level_str: str) -> str:
455 """Create a timestamped run dir and attach a file handler. Returns the run dir."""
456 import datetime
457
458 log_level = getattr(logging, log_level_str.upper())
459 timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
460 run_dir = os.path.join(_LOGS_ROOT, timestamp)
461 os.makedirs(run_dir, exist_ok=True)
462 log_path = os.path.join(run_dir, "run.log")
463
464 file_handler = logging.FileHandler(log_path)
465 file_handler.setLevel(log_level)
466 file_handler.setFormatter(logging.Formatter(_LOG_FMT, datefmt=_LOG_DATEFMT))
467 logging.getLogger("explainshell").addHandler(file_handler)
468
469 # Logged after the file handler is attached so the run log captures it.
470 logger.info("command line: %s", " ".join(sys.argv))
471 logger.info("logging to %s", log_path)
472 return run_dir
473
474
475def _ensure_run_dir(ctx: click.Context) -> str:

Callers 1

_ensure_run_dirFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected