Version 1
This commit is contained in:
33
linedance-app/app_logger.py
Normal file
33
linedance-app/app_logger.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
app_logger.py — Central logging til fil i stedet for konsol.
|
||||
P<EFBFBD> Windows uden konsol skrives alt til ~/.linedance/app.log
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
LOG_PATH = Path.home() / ".linedance" / "app.log"
|
||||
|
||||
|
||||
def setup_logging():
|
||||
LOG_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
handlers = [logging.FileHandler(LOG_PATH, encoding="utf-8")]
|
||||
# Kun tilføj konsol-handler hvis vi kører med konsol (development)
|
||||
if sys.stdout and hasattr(sys.stdout, 'write'):
|
||||
try:
|
||||
sys.stdout.write("") # test om konsol virker
|
||||
handlers.append(logging.StreamHandler(sys.stdout))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||||
datefmt="%H:%M:%S",
|
||||
handlers=handlers,
|
||||
force=True,
|
||||
)
|
||||
|
||||
|
||||
logger = logging.getLogger("linedance")
|
||||
Reference in New Issue
Block a user