Spaces:
Configuration error
Configuration error
File size: 1,136 Bytes
ab028ac |
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 37 38 39 40 41 42 43 44 45 46 47 |
"""
Utility functions for the application.
"""
import logging
import traceback
from datetime import datetime
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('app.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def log_error(message, exception=None):
"""Log error message with optional exception details."""
if exception:
logger.error(f"{message}: {str(exception)}")
logger.error(traceback.format_exc())
else:
logger.error(message)
def log_info(message):
"""Log info message."""
logger.info(message)
def get_timestamp():
"""Get current timestamp as string."""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def sanitize_filename(filename):
"""Sanitize filename for safe file operations."""
# Remove or replace unsafe characters
unsafe_chars = ['<', '>', ':', '"', '/', '\\', '|', '?', '*']
for char in unsafe_chars:
filename = filename.replace(char, '_')
return filename.strip() |