globalMOO Documentation
  • globalMOO API Documentation
  • core
    • Authentication
    • Core Concepts
    • Getting Started with globalMOO
    • Error Handling
    • Event Handling
    • SDK Initialization
    • Debugging & Logging
  • schemas
    • Account Schema
    • Model Schema
    • Project Schema
    • Trial Schema
    • Objective Schema
    • Result Schema
    • Inverse Schema
  • quickstart
    • Your First Optimization with globalMOO
  • endpoints
    • accounts
      • Account Endpoints
      • Register Account
    • inverse
      • Inverse Optimization Endpoints
      • Initialize Inverse Optimization
      • Load Inverse Output
      • Suggest Inverse Step
    • models
      • Create Model
      • Model Endpoints
      • List Models
    • objectives
      • Objective Endpoints
      • Load Objectives
    • outputs
      • Output Endpoints
      • Load Output Cases
      • Load Developed Outputs
    • projects
      • Create Project
      • Project Endpoints
    • trials
      • Trial Endpoints
      • Read Trial
Powered by GitBook
On this page
  • Debug Mode
  • Log Levels
  • Custom Logging
  • What Gets Logged
  • Log Output Example
  • Best Practices
  1. core

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

use GlobalMoo\Client;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;

// Create logger
$logger = new Logger('globalmoo');

// Configure handler
$handler = new StreamHandler('php://stdout', Logger::DEBUG);
$handler->setFormatter(new LineFormatter(
    format: null,
    dateFormat: null,
    allowInlineLineBreaks: true,
    ignoreEmptyContextAndExtra: true
));

$logger->pushHandler($handler);

// Create client with debug mode
$client = new Client(debug: true);
const { Client } = require('globalmoo');

// Create client with debug configuration
const client = new Client({
    debug: true,
    logger: {
        debug: console.debug,
        info: console.info,
        warn: console.warn,
        error: console.error
    }
});

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)
use Monolog\Logger;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Processor\IntrospectionProcessor;

// Create logger
$logger = new Logger('globalmoo');

// Add file handler
$fileHandler = new RotatingFileHandler(
    'globalmoo.log',
    maxFiles: 5,
    level: Logger::DEBUG
);
$fileHandler->setFormatter(new LineFormatter());

// Add console handler
$consoleHandler = new StreamHandler('php://stdout');
$consoleHandler->setFormatter(new LineFormatter());

// Add processors
$logger->pushProcessor(new IntrospectionProcessor());

// Add handlers
$logger->pushHandler($fileHandler);
$logger->pushHandler($consoleHandler);
const winston = require('winston');

// Create custom logger
const logger = winston.createLogger({
    level: 'debug',
    format: winston.format.combine(
        winston.format.timestamp(),
        winston.format.json()
    ),
    transports: [
        // Write to all logs
        new winston.transports.File({ 
            filename: 'globalmoo.log',
            maxsize: 1024 * 1024, // 1MB
            maxFiles: 5
        }),
        // Write to console
        new winston.transports.Console({
            format: winston.format.simple()
        })
    ]
});

// Create client with custom logger
const client = new Client({
    debug: true,
    logger: logger
});

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

PreviousSDK InitializationNextschemas

Last updated 3 months ago