---
title: "Flush logs"
section: "frontend/logging"
platforms: ["android", "swift"]
gen: 2
last-updated: "2026-03-25T17:40:00.000Z"
url: "https://docs.amplify.aws/react/frontend/logging/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](#change-automatic-log-flush-interval). 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:

<!-- Platform: android -->

  #### [With Configuration File]
Update the `flushIntervalInSeconds` field in the logging configuration file.

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

  
  #### [With Code]
Provide a `flushIntervalInSeconds` parameter initialization and configuration of the `AWSCloudWatchLoggingPlugin`.

#### [Java]

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

#### [Kotlin]

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

#### [RxJava]

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

  

<!-- /Platform -->

<!-- Platform: swift -->

  #### [With Configuration File]
Update the `flushIntervalInSeconds` field in the logging configuration file.

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

  
  #### [With Code]
Provide a `flushIntervalInSeconds` parameter initialization and configuration of the `AWSCloudWatchLoggingPlugin`.

```swift
do {
    let loggingConfiguration = AWSCloudWatchLoggingPluginConfiguration(logGroupName: "<log-group-name>", region: "<region>", flushIntervalInSeconds: 120)
    let loggingPlugin = AWSCloudWatchLoggingPlugin(loggingPluginConfiguration: loggingConfiguration)
    try Amplify.add(plugin: loggingPlugin)
    try Amplify.configure(with: .amplifyOutputs)
} catch {
    assert(false, "Error initializing Amplify: \(error)")
}
```

  

<!-- /Platform -->

## 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.

<!-- Platform: android -->

#### [Java]
Add import statement to the `AWSCloudWatchLoggingPlugin`
```java
import com.amplifyframework.logging.cloudwatch.AWSCloudWatchLoggingPlugin;
```

Execute the flush log function from the plugin.

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

#### [Kotlin]

Add import statement to the `AWSCloudWatchLoggingPlugin`
```kotlin
import com.amplifyframework.logging.cloudwatch.AWSCloudWatchLoggingPlugin
```

Execute the flush log function from the plugin.

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

#### [RxJava]

Add import statement to the `AWSCloudWatchLoggingPlugin`
```java
import com.amplifyframework.logging.cloudwatch.AWSCloudWatchLoggingPlugin;
```

Execute the flush log function from the plugin.

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

<!-- /Platform -->

<!-- Platform: swift -->
Add import statement to the `AWSCloudWatchLoggingPlugin`
```swift
import AWSCloudWatchLoggingPlugin
```

Execute the flush log function from the plugin.

```swift
let cloudWatchPlugin = try Amplify.Logging.getPlugin(for: "awsCloudWatchLoggingPlugin") as? AWSCloudWatchLoggingPlugin
try await cloudWatchPlugin?.flushLogs()
```
<!-- /Platform -->
