Skip to content

Framework Integration Overview

LogXide integrates with popular Python web frameworks. The integration pattern is simple: replace import logging with from logxide import logging.

Quick Start

For all frameworks, the integration is identical:

from logxide import logging

# Configure logging as you normally would
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# Use standard logging throughout your application
logger = logging.getLogger(__name__)

Framework Guides

Best Practices

1. Structured Logging

Use structured formats for better observability:

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - '
           '[%(process)d:%(thread)d] - %(funcName)s:%(lineno)d - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S'
)

2. Logger Hierarchy

Organize loggers for granular control:

app_logger = logging.getLogger('myapp')
db_logger = logging.getLogger('myapp.database')
auth_logger = logging.getLogger('myapp.auth')
api_logger = logging.getLogger('myapp.api')

3. Context Information

Include relevant context in log messages:

logger.info(f'User {user_id} accessed {endpoint} from {ip_address}')
logger.info(f'Database query completed in {duration:.3f}s')
logger.info(f'[{transaction_id}] Processing payment for user {user_id}')

4. Proper Flush

Always flush before shutdown:

# Before application shutdown
@app.on_event("shutdown")
async def shutdown_event():
    logging.flush()

# After critical operations
try:
    critical_operation()
    logger.info("Critical operation completed")
    logging.flush()
except Exception as e:
    logger.error(f"Critical operation failed: {e}")
    logging.flush()
    raise

Troubleshooting

Common Issues

  1. LogXide not capturing framework logs
  2. Ensure you use from logxide import logging
  3. Check that the framework's logging configuration isn't overriding LogXide

  4. Missing log messages

  5. Call logging.flush() before application shutdown
  6. Check if log levels are filtering out messages

  7. Performance not as expected

  8. Check log levels — debug logging can impact performance
  9. Use logging.flush() only when necessary

Debug Configuration

from logxide import logging

logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# Enable debug for specific components
logging.getLogger('werkzeug').setLevel(logging.DEBUG)  # Flask
logging.getLogger('django').setLevel(logging.DEBUG)    # Django
logging.getLogger('uvicorn').setLevel(logging.DEBUG)   # FastAPI