Automated Action b51b13eb3e Create backend scaffold for freelancer invoicing API
- Set up FastAPI application with CORS support
- Configure SQLite database connection
- Create database models for users, clients, invoices, and line items
- Set up Alembic for database migrations
- Implement JWT-based authentication system
- Create basic CRUD endpoints for users, clients, and invoices
- Add PDF generation functionality
- Implement activity logging
- Update README with project information
2025-05-26 18:21:20 +00:00

34 lines
1.1 KiB
Python

import sys
from pathlib import Path
from loguru import logger
LOG_DIR = Path("/app") / "storage" / "logs"
LOG_DIR.mkdir(parents=True, exist_ok=True)
LOG_FILE = LOG_DIR / "app.log"
# Configure loguru logger
logger.remove() # Remove default handler
logger.add(sys.stderr, level="INFO") # Add stderr handler
logger.add(
LOG_FILE,
rotation="10 MB", # Rotate when file reaches 10 MB
retention="30 days", # Keep logs for 30 days
compression="zip", # Compress rotated logs
level="DEBUG",
)
# Create a function to log user activity
def log_activity(user_id: str, action: str, object_type: str, object_id: str = None):
"""
Log user activity.
Args:
user_id: ID of the user performing the action
action: The action performed (e.g., "create", "update", "delete")
object_type: The type of object the action was performed on (e.g., "invoice", "client")
object_id: The ID of the object the action was performed on (optional)
"""
if object_id:
logger.info(f"User {user_id} {action}d {object_type} {object_id}")
else:
logger.info(f"User {user_id} {action}d {object_type}")