Logging - AWS SDK for Swift


The AWS SDK for Swift uses Apple’s SwiftLog mechanism to log informational and debugging messages to the console. The output from the logging system appears in the console provided by most IDEs, as well as the standard system console.

By default, the logging system only outputs informational and more critical error messages, rather than detailed debugging information. To see debug-level output, you need to change the logging level to debug. You do this using the SDKLoggingSystem object provided by the ClientRuntime package. In this guide, you’ll learn how to control not only the global output level, but also the logging level on a service-by-service basis.

Enabling debug output

Detailed debugging information is output by the SDK for Swift using the debug log level, which is not visible in the console by default. To see these messages, you’ll need to change the logging system’s log level as shown below.

import ClientRuntime SDKLoggingSystem.initialize(logLevel: .debug)

Call SDKLoggingSystem.initialize() only once in your application, during startup.

Logging levels

The log levels supported by the SDK for Swift are identified by the values of the SDKLogLevel Swift enum. Each log level is inclusive of the messages at and below that level. For example, setting the log level to warning also causes log messages to be output for levels error and critical.

The supported log levels (from least severe to most severe) are:

  • .trace

  • .debug

  • .info

  • .notice (the default)

  • .warning

  • .error

  • .critical

Setting the logging level for specific services

You can also manage the log level of specific services, rather than setting a single log level for the entire SDK for Swift. This is done using the SDKLoggingSystem method add(). This method connects a given AWS service client’s logging handler to the logging system.

For example, to set the logging level for Amazon S3 calls to debug and the logging level for Amazon Cognito Identity to info, you would use the following code.

import AWSCognitoIdentity import AWSS3 import ClientRuntime SDKLoggingSystem.add(logHandlerFactory: CognitoIdentityClientLogHandlerFactory(logLevel: .info)) SDKLoggingSystem.add(logHandlerFactory: S3ClientLogHandlerFactory(logLevel: .info)) SDKLoggingSystem.initialize()