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

Flush logs

When using the Amplify Logger, all logged messages are saved locally on the user's device first and then flushed at a set interval that you can customize. You can also choose to flush events manually if needed by following the steps outlined in this section.

Change automatic log flush interval

You can customize the time interval for when logs are automatically flushed and sent to CloudWatch.

Below is an example of setting the time interval to 120 seconds:

Update the flushIntervalInSeconds field in the logging configuration file.

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

Provide a flushIntervalInSeconds parameter initialization and configuration of the AWSCloudWatchLoggingPlugin.

AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>, <region>, 120);
Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));
val config = AWSCloudWatchLoggingPluginConfiguration(logGroupName = <log-group-name>, region = <region>, flushIntervalInSeconds = 120)
Amplify.addPlugin(AWSCloudWatchLoggingPlugin(config))
AWSCloudWatchLoggingPluginConfiguration config = new AWSCloudWatchLoggingPluginConfiguration (<log-group-name>,<region>, 120);
Amplify.addPlugin(new AWSCloudWatchLoggingPlugin(config));

Manually flush logs

You can choose at anytime to flush the log messages that are saved locally on the user's device, to then send them immediately to Amazon CloudWatch.

Add import statement to the AWSCloudWatchLoggingPlugin

import com.amplifyframework.logging.cloudwatch.AWSCloudWatchLoggingPlugin;

Execute the flush log function from the plugin.

AWSCloudWatchLoggingPlugin plugin = (AWSCloudWatchLoggingPlugin)Amplify.Logging.getPlugin("awsCloudWatchLoggingPlugin");
plugin.flushLogs(
() -> {
// logs flushed successfully
}, error -> {
// failed to flush logs
}
);

Add import statement to the AWSCloudWatchLoggingPlugin

import com.amplifyframework.logging.cloudwatch.AWSCloudWatchLoggingPlugin

Execute the flush log function from the plugin.

val plugin = Amplify.Logging.getPlugin("awsCloudWatchLoggingPlugin") as? AWSCloudWatchLoggingPlugin
plugin?.flushLogs(
{
// logs flushed successfully
},{ error ->
// failed to flush logs
}
);

Add import statement to the AWSCloudWatchLoggingPlugin

import com.amplifyframework.logging.cloudwatch.AWSCloudWatchLoggingPlugin;

Execute the flush log function from the plugin.

AWSCloudWatchLoggingPlugin plugin = (AWSCloudWatchLoggingPlugin)Amplify.Logging.getPlugin("awsCloudWatchLoggingPlugin");
plugin.flushLogs(
() -> {
// logs flushed successfully
}, error -> {
// failed to flush logs
}
);