File size: 1,079 Bytes
14cb7ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# models/logging_config.py
import os
import logging
def setup_logging():
log_dir = os.environ.get('LOG_DIR', '/app/logs')
try:
os.makedirs(log_dir, exist_ok=True)
log_file = os.path.join(log_dir, 'app.log')
# Ensure log file exists and is writable
if not os.path.exists(log_file):
open(log_file, 'a').close()
os.chmod(log_file, 0o666)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_file),
logging.StreamHandler()
]
)
return logging.getLogger(__name__)
except Exception as e:
# Fallback to console-only logging if file logging fails
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[logging.StreamHandler()]
)
return logging.getLogger(__name__)
logger = setup_logging()
|