""" 환경변수 게이트 디버그 로깅. `CLOCKOUT_DEBUG=1` 환경변수가 설정된 경우에만 stderr/파일로 출력. 프로덕션 빌드(PyInstaller)에서 항상 켜두지 않도록 게이트 처리. """ import os import sys from datetime import datetime from pathlib import Path _DEBUG_ENV = os.environ.get('CLOCKOUT_DEBUG', '').strip() in ('1', 'true', 'yes') _LOG_DIR = Path(os.environ.get('CLOCKOUT_DEBUG_DIR') or Path.home() / '.clockout_logs') _LOG_FILE = _LOG_DIR / 'debug.log' def is_debug() -> bool: return _DEBUG_ENV def dlog(*args, file: str = None) -> None: """디버그 모드에서만 stderr + 파일로 기록. 비활성화 시 no-op.""" if not _DEBUG_ENV: return msg = f"[{datetime.now().strftime('%H:%M:%S')}] " + ' '.join(str(a) for a in args) print(msg, file=sys.stderr) try: target = Path(file) if file else _LOG_FILE target.parent.mkdir(parents=True, exist_ok=True) with open(target, 'a', encoding='utf-8') as f: f.write(msg + '\n') except OSError: pass