---
title: "Send 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/send-logs/"
---

With the Amplify Logger, you can send logs to Amazon CloudWatch from errors that are caught by the Amplify library or by adding your own custom log messages. You can also customize which levels of log messages to send to CloudWatch.

## Log messages

<Callout>

You should follow best security practices when logging messages. This includes validating log messages and ensuring log messages don't contain personally identifiable information and/or sensitive data.

</Callout>

You can log messages using the Amplify logger to a specific namespace to help you group logs that are similar when they are sent to CloudWatch. To accomplish this, get an instance of the `Logger` and specify a `category name` and/or `namespace`. Use the `Logger` instance to log messages at the desired log level. The `category name` and `namespace` values are used to tag your log messages that will appear in CloudWatch. They are also used to identify and fetch the logger again without creating a new `Logger` instance.

You can also log JSON formatted log messages to leverage [AWS CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html) query and filter supports.

<!-- Platform: android -->

#### [Java]

```java
Logger logger = Amplify.Logging.logger(AmplifyCategory.Auth, "<namespace>")
try {
  String result = doSomething();
  logger.debug("result: " + result);
} catch(Exception: exception) {
  logger.error("operation failed", exception);
}

```

#### [Kotlin]

```kotlin
val logger = Amplify.Logging.logger(AmplifyCategory.Auth, "<namespace>")
try {
  val result = doSomething()
  logger.debug("result: $result")
} catch (exception: Exception) {
  logger.error("operation failed", exception)
}
```

#### [RxJava]

```java
Logger logger = Amplify.Logging.logger(AmplifyCategory.Auth, "<namespace>")
try {
  String result = doSomething();
  logger.debug("result: " + result);
} catch(Exception: exception) {
  logger.error("operation failed", exception);
}
```

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`
<!-- /Platform -->

<!-- Platform: swift -->
```swift
let logger = Amplify.Logging.logger(forCategory: "Authentication", forNamespace: "<your-code-namespace>")
do {
    let jsonEncoder = JSONEncoder()
    let person = Person(firstName: "John", lastName: "Doe", age: 25)
    let jsonData = try jsonEncoder.encode(person)
    let jsonString = String(data: jsonData, encoding: String.Encoding.utf8)!
    logger.debug(jsonString)
} catch {
    logger.error("Error encoding person instance")
}
```

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`
<!-- /Platform -->
