Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

Change log levels

In this section, you will learn about how to configure the logging level in your application when using the Amplify logger. This is helpful to help you determine the logging level that works best for your use cases, and which levels of errors or warnings you want to capture in Amazon Cloudwatch.

Change Default Log Level

Below is an example of setting the default log level to WARN:

Update the defaultLogLevel field under loggingConstraints.

{
"awsCloudWatchLoggingPlugin": {
"enable": true,
"logGroupName": "<log-group-name>",
"region": "<region>",
"localStoreMaxSizeInMB": 1,
"flushIntervalInSeconds": 60,
"loggingConstraints": {
"defaultLogLevel": "WARN"
}
}
}

The following are supported log levels:

  • ERROR
  • WARN
  • INFO
  • DEBUG
  • VERBOSE
  • NONE

Setting the log level to NONE effectively disables logging.

Provide a default log level at initialization and configuration of the AWSCloudWatchLoggingPlugin.

do {
let loggingConstraints = LoggingConstraints(defaultLogLevel: .warn)
let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "<log-group-name>", region: "<region>", loggingConstraints: loggingConstraints)
let loggingPlugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration)
try Amplify.add(plugin: loggingPlugin)
} catch {
assert(false, "Error initializing Amplify: \(error)")
}

The following are supported log levels:

LogLevel.error
LogLevel.warn
LogLevel.info
LogLevel.debug
LogLevel.verbose
LogLevel.none

Setting the log level to LogLevel.none effectively disables logging.

Configure Log Level by Category

Each Amplify category can be configured to have its own logging level.

Below is an example of setting different logging levels for the Storage and Auth categories.

Add a categoryLogLevel section and specify each category and its log level.

{
"awsCloudWatchLoggingPlugin": {
"enable": true,
"logGroupName": "<log-group-name>",
"region": "<region>",
"localStoreMaxSizeInMB": 1,
"flushIntervalInSeconds": 60,
"loggingConstraints": {
"defaultLogLevel": "ERROR",
"categoryLogLevel": {
"Authentication": "VERBOSE",
"Storage": "DEBUG"
}
}
}
}

To disable logging for a specific category, set the log level to NONE.

Provide a dictionary of category and corresponding log levels at initialization and configuration of the AWSCloudWatchLoggingPlugin.

do {
let categoryLogLevels: [String: LogLevel] = ["Authentication": .verbose, "Storage": .debug]
let loggingConstraints = LoggingConstraints(defaultLogLevel: .warn, categoryLogLevel: categoryLogLevels)
let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "<log-group-name>", region: "<region>", loggingConstraints: loggingConstraints)
let loggingPlugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration)
try Amplify.add(plugin: loggingPlugin)
} catch {
assert(false, "Error initializing Amplify: \(error)")
}

To disable logging for a specific category, set the log level to LogLevel.none.

The following are existing Amplify category names that are used by default by Amplify when automatically logging errors from the library.

  • Analytics
  • API
  • Authentication
  • DataStore
  • Geo
  • Hub
  • Logging
  • Predictions
  • PushNotifications
  • Storage