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.
- PHP
- Python
- Ruby
- Go
- C#
$client = SdkClientBuilder::init()
->loggingConfiguration(
LoggingConfigurationBuilder::init()
->level(LogLevel::INFO)
->maskSensitiveHeaders(true)
->requestConfiguration(
RequestLoggingConfigurationBuilder::init()
->body(true)
->headers(true)
->includeQueryInPath(true)
->includeHeaders('Content-Type', 'Content-Encoding')
)
->responseConfiguration(
ResponseLoggingConfigurationBuilder::init()
->headers(true)
->excludeHeaders('X-Powered-By')
)
)
->build();
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']
)
)
)
client = SDKClient.new(
logging_configuration: LoggingConfiguration.new(
log_level: Logger::INFO,
mask_sensitive_headers: true,
request_logging_config: RequestLoggingConfiguration.new(
log_body: true,
log_headers: true,
include_query_in_path: true,
headers_to_include: %w[Content-Type Content-Encoding]
),
response_logging_config: ResponseLoggingConfiguration.new(
log_headers: true,
headers_to_exclude: ['X-Powered-By']
)
)
)
config := CreateConfigurationFromEnvironment(
WithLoggerConfiguration(
WithLevel("info"),
WithMaskSensitiveHeaders(true),
WithRequestConfiguration(
WithRequestBody(true),
WithRequestHeaders(true),
WithIncludeQueryInPath(true),
WithIncludeRequestHeaders("Content-Type", "Content-Encoding"),
),
WithResponseConfiguration(
WithResponseHeaders(true),
WithExcludeResponseHeaders("X-Powered-By"),
),
),
)
client := NewClient(config)
SdkClient client = new SdkClient.Builder()
.LoggingConfig(config => config
.LogLevel(LogLevel.Information)
.MaskSensitiveHeaders(true)
.RequestConfig(reqConfig => reqConfig
.Body(true)
.Headers(true)
.IncludeQueryInPath(true)
.IncludeHeaders("Content-Type", "Content-Encoding"))
.ResponseConfig(respConfig => respConfig
.Headers(true)
.ExcludeHeaders("X-Powered-By"))
)
.Build();