Debugging & Logging

The globalMOO SDKs provide extensive debugging and logging capabilities to help troubleshoot integration issues.

Debug Mode

Enable debug mode for detailed logging of API interactions:

from globalmoo.client import Client
import logging

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

# Create client with debug mode
client = Client(debug=True)

Debug mode will log:

  • Request URLs and methods

  • Request headers and bodies

  • Response status codes

  • Response headers and bodies

  • Validation errors

  • SDK operations

Log Levels

The SDKs use these standard log levels:

Level
Description
Examples

DEBUG

Detailed troubleshooting

Request/response bodies, validation details

INFO

General operations

Request initiated, response received

WARNING

Potential issues

Rate limit warning, retry attempt

ERROR

Operation failures

Network error, invalid response

Custom Logging

Configure custom logging behavior:

import logging
from logging.handlers import RotatingFileHandler

# Create custom logger
logger = logging.getLogger('globalmoo')
logger.setLevel(logging.DEBUG)

# Create handlers
file_handler = RotatingFileHandler(
    'globalmoo.log',
    maxBytes=1024*1024,  # 1MB
    backupCount=5
)
console_handler = logging.StreamHandler()

# Create formatters
formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)

# Add handlers to logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)

What Gets Logged

With debug mode enabled, the SDKs log:

  1. Request Information

    • HTTP method and URL

    • Request headers

    • Request body

    • Query parameters

  2. Response Information

    • Status code

    • Response headers

    • Response body

    • Timing information

  3. SDK Operations

    • Object creation

    • Validation steps

    • Data transformations

    • Error handling

  4. Performance Metrics

    • Request duration

    • Suggestion time

    • Computation time

    • Network latency

Log Output Example

2025-01-31 10:00:00,123 - globalmoo - DEBUG - Request: POST https://app.globalmoo.com/api/models
2025-01-31 10:00:00,124 - globalmoo - DEBUG - Headers: {
    "Authorization": "Bearer [FILTERED]",
    "Content-Type": "application/json"
}
2025-01-31 10:00:00,125 - globalmoo - DEBUG - Body: {
    "name": "Test Model"
}
2025-01-31 10:00:00,234 - globalmoo - DEBUG - Response: 201 Created
2025-01-31 10:00:00,235 - globalmoo - DEBUG - Body: {
    "id": 123,
    "name": "Test Model",
    "created_at": "2025-01-31T10:00:00.000Z"
}
2025-01-31 10:00:00,236 - globalmoo - INFO - Created model 123

Best Practices

  1. Log Management

    • Use log rotation to manage file size

    • Clean up old log files

    • Consider log aggregation for production

    • Monitor log volume

  2. Security

    • Never log API keys or credentials

    • Redact sensitive information

    • Secure log file permissions

    • Follow data privacy regulations

  3. Performance

    • Use appropriate log levels

    • Consider logging impact

    • Buffer log writes

    • Compress old logs

  4. Troubleshooting

    • Include correlation IDs

    • Log context information

    • Use structured logging

    • Add timing information

Last updated