Skip to main content

Logging

APIMatic's SDKs enable developers to conveniently log SDK activities using their preferred loggers. This capability is a vital tool for debugging and optimizing SDK performance in both production and development environments.

Key Benefits

  • Enhanced Debugging: Easily track API calls, responses, and errors within the SDK, simplifying the process of identifying and resolving issues.
  • Comprehensive Monitoring: Monitor SDK performance and behavior through detailed logs, ensuring smoother integration and maintenance.
  • Cross-Language Consistency: Consistent logging support across PHP, Ruby, C#, and Python ensures a unified experience for developers working in multiple ecosystems.
  • Customizable Logging Levels: Control the granularity of logs to suit development, testing, or production environments.
  • Sensitive Data Masking: Automatically masks sensitive headers in logs, ensuring secure handling of confidential information.

How to Configure Logging

  1. Enable Logging:

  2. Specify Log Levels:

    • Choose the desired log level (for example, DEBUG, INFO, ERROR).
    • Update the SDK configuration to include the selected log level.
  3. Configure logging:

    • Request Logging Options

      • Log Body: Controls the logging of the request body.
      • Log Headers: Controls the logging of request headers.
      • Exclude Headers: Excludes specified headers from the log output.
      • Include Headers: Includes only specified headers in the log output.
      • Unmask Headers: Logs specified headers without masking, revealing their actual values.
      • Include Query in Path: Determines whether to include query parameters in the logged request path.
    • Response Logging Options

      • Log Body: Controls the logging of the response body.
      • Log Headers: Controls the logging of response headers.
      • Exclude Headers: Excludes specified headers from the log output.
      • Include Headers: Includes only specified headers in the log output.
      • Unmask Headers: Logs specified headers without masking, revealing their actual values.
const client = new SDKClient({
logging: {
logLevel: LogLevel.Debug,
maskSensitiveHeaders: true,
logRequest: {
logBody: true,
logHeaders: true,
includeQueryInPath: true,
headersToInclude: ["Content-Type", "Content-Encoding"]
},
logResponse: {
logHeaders: true,
headersToExclude: ["X-Powered-By"]
}
}
});

Use Cases

  • Error Diagnosis: Quickly identify and troubleshoot errors in API calls.
  • Performance Monitoring: Analyze response times and performance metrics for API operations.
  • Compliance Tracking: Maintain logs for audit trails and compliance purposes.
  • Development Insights: Gain detailed insights into SDK usage during development.