Skip to main content

Introducing Configurable Logging Support in PHP, Python, Ruby, Go, and C# SDKs

· 3 min read

We have introduced configurable logging for API calls in PHP, Python, Ruby, Go, and C# SDKs.

In one of our previous updates, we introduced the configurable logging feature in both Java and TypeScript SDKs. You can find more details here.

What's New?

Logging in a software application is essential when it comes to capturing activity data for troubleshooting, security auditing, and performance analysis. This feature can now be activated in SDKs using the EnableLogging codegen setting.

info:
x-codegen-settings:
EnableLogging: true

For more details on the EnableLogging CodegenSetting and its impact on SDK behavior, please refer to the EnableLogging documentation.

Below are the logging configuration options that users can apply when logging API calls.

General Logging Configuration Options

  • Level: Defines the log message severity or priority (e.g., DEBUG, INFO, WARN, ERROR, FATAL).
  • Logger: Allows users to provide a custom logger implementation.
  • Mask Sensitive Headers: A global setting to mask sensitive HTTP headers in both requests and responses before logging, safeguarding confidential data.

Request Logging Configuration 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 Configuration 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.

These configurations can be set during SDK client initialization. Below are examples demonstrating how to use these configurations in various programming languages.

client = SDKClient(
logging_configuration=LoggingConfiguration(
log_level=logging.INFO,
mask_sensitive_headers=True,
request_logging_config=RequestLoggingConfiguration(
log_body=True,
log_headers=True,
include_query_in_path=True,
headers_to_include=['Content-Type', 'Content-Encoding']
),
response_logging_config=ResponseLoggingConfiguration(
log_headers=True,
headers_to_exclude=['X-Powered-By']
)
)
)