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.

LoggingConstraints loggingConstraints = new LoggingConstraints(LogLevel.WARN);
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>, <region>, loggingConstraints);
Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));
val loggingConstraints = LoggingConstraints(defaultLogLevel = LogLevel.WARN)
val config = AWSCloudWatchLoggingPluginConfiguration(logGroupName = <log-group-name>, region = <region>, loggingConstraints = loggingConstraints)
Amplify.addPlugin(AWSCloudWatchLoggingPlugin(config))
LoggingConstraints loggingConstraints = new LoggingConstraints(LogLevel.WARN);
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>,<region>, loggingConstraints);
Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));

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 map of category and corresponding log levels at initialization and configuration of the AWSCloudWatchLoggingPlugin.

Map<CategoryType, LogLevel> categoryOverrides = new HashMap<>();
categoryOverrides.put(CategoryType.AUTH, LogLevel.VERBOSE);
categoryOverrides.put(CategoryType.STORAGE, LogLevel.DEBUG);
LoggingConstraints loggingConstraints = new LoggingConstraints(LogLevel.WARN, categoryOverrides);
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>, <region>, loggingConstraints);
Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));
val categoryOverrides = mapOf<CategoryType, LogLevel>(CategoryType.AUTH to LogLevel.VERBOSE, CategoryType.STORAGE to LogLevel.DEBUG)
val loggingConstraints = LoggingConstraints(defaultLogLevel = LogLevel.WARN, categoryLogLevel = categoryOverrides)
val config = AWSCloudWatchLoggingPluginConfiguration(logGroupName = <log-group-name>, region = <region>, loggingConstraints = loggingConstraints)
Amplify.addPlugin(AWSCloudWatchLoggingPlugin(config))
Map<CategoryType, LogLevel> categoryOverrides = new HashMap<>();
categoryOverrides.put(CategoryType.AUTH, LogLevel.VERBOSE);
categoryOverrides.put(CategoryType.STORAGE, LogLevel.DEBUG);
LoggingConstraints loggingConstraints = new LoggingConstraints(LogLevel.WARN, categoryOverrides);
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>,<region>, loggingConstraints);
Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));

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

  • ANALYTICS
  • API
  • AUTH
  • DATASTORE
  • HUB
  • LOGGING
  • NOTIFICATIONS
  • PREDICTIONS
  • STORAGE
  • GEO