Skip to content

Commit

Permalink
Update Android SDK with log filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
novalisdenahi committed Nov 27, 2024
1 parent 59aaa12 commit 8fba4e8
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions website/docs/sdk-reference/android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,19 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#", options -> {

These are the available options on the `Options` class:

| Options | Description |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Options | Description |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dataGovernance(DataGovernance)` | Optional, defaults to `Global`. Describes the location of your feature flag and setting data within the ConfigCat CDN. This parameter needs to be in sync with your Data Governance preferences. [More about Data Governance](../advanced/data-governance.mdx). Available options: `Global`, `EuOnly`. |
| `baseUrl(string)` | Optional, sets the CDN base url (forward proxy, dedicated subscription) from where the sdk will download the config JSON. |
| `httpClient(OkHttpClient)` | Optional, sets the underlying `OkHttpClient` used to download the feature flags and settings over HTTP. [More about the HTTP Client](#httpclient). |
| `cache(ConfigCache)` | Optional, sets a custom cache implementation for the client. [More about cache](#custom-cache). |
| `pollingMode(PollingMode)` | Optional, sets the polling mode for the client. [More about polling modes](#polling-modes). |
| `logLevel(LogLevel)` | Optional, defaults to `WARNING`. Sets the internal log level. [More about logging](#logging). |
| `flagOverrides(OverrideDataSourceBuilder, OverrideBehaviour)` | Optional, sets the local feature flag & setting overrides. [More about feature flag overrides](#flag-overrides). |
| `defaultUser(User)` | Optional, sets the default user. [More about default user](#default-user). |
| `offline(boolean)` | Optional, defaults to `false`. Indicates whether the SDK should be initialized in offline mode. [More about offline mode](#online--offline-mode). |
| `hooks()` | Optional, used to subscribe events that the SDK sends in specific scenarios. [More about hooks](#hooks). |
| `baseUrl(string)` | Optional, sets the CDN base url (forward proxy, dedicated subscription) from where the sdk will download the config JSON. |
| `httpClient(OkHttpClient)` | Optional, sets the underlying `OkHttpClient` used to download the feature flags and settings over HTTP. [More about the HTTP Client](#httpclient). |
| `cache(ConfigCache)` | Optional, sets a custom cache implementation for the client. [More about cache](#custom-cache). |
| `pollingMode(PollingMode)` | Optional, sets the polling mode for the client. [More about polling modes](#polling-modes). |
| `logLevel(LogLevel)` | Optional, defaults to `WARNING`. Sets the internal log level. [More about logging](#logging). |
| `flagOverrides(OverrideDataSourceBuilder, OverrideBehaviour)` | Optional, sets the local feature flag & setting overrides. [More about feature flag overrides](#flag-overrides). |
| `defaultUser(User)` | Optional, sets the default user. [More about default user](#default-user). |
| `offline(boolean)` | Optional, defaults to `false`. Indicates whether the SDK should be initialized in offline mode. [More about offline mode](#online--offline-mode). |
| `hooks()` | Optional, used to subscribe events that the SDK sends in specific scenarios. [More about hooks](#hooks). |
| `logFilter(LogFilterFunction)` | Optional, sets a custom log filter. [More about log filtering](#log-filtering). |

:::caution
We strongly recommend you to use the `ConfigCatClient` as a Singleton object in your application.
Expand Down Expand Up @@ -671,6 +672,22 @@ You have the flexibility to use any slf4j implementation for logging with Config
Examples for <a href="https://github.com/configcat/android-sdk/blob/master/samples/android-kotlin/app/src/android-logger.properties" target="_blank">android-logger</a> and <a href="https://github.com/configcat/android-sdk/blob/master/samples/android-java/app/src/main/assets/logback.xml" target="_blank">logback</a> are available under the [Sample Apps](#sample-apps) section.
### Log Filtering
You can define a custom log filter by implementing the `LogFilterFunction` interface. The `apply` method will be called by the _ConfigCat SDK_ each time a log event occurs (and the event passes the minimum log level specified by the `logLevel` option). That is, the `apply` method allows you to filter log events by `logLevel`, `eventId`, `message` or `exception`. The formatted message string can be obtained by calling `toString()` on the `message` parameter.
If the `apply` method returns `true`, the event will be logged, otherwise it will be skipped.
```java
// Filter out events with id 1001 from the log.
LogFilterFunction filterLogFunction = ( LogLevel logLevel, int eventId, Object message, Throwable exception) -> eventId != 1001;
ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#", options -> options.logFilter(filterLogFunction));
```
:::caution
Please make sure that your log filter logic doesn't perform heavy computation and doesn't block the executing thread. A complex or incorrectly implemented log filter can degrade the performance of the SDK.
:::
## Sensitive information handling
The frontend/mobile SDKs are running in your users' browsers/devices. The SDK is downloading a [config JSON](../requests.mdx) file from ConfigCat's CDN servers. The URL path for this config JSON file contains your SDK key, so the SDK key and the content of your config JSON file (feature flag keys, feature flag values, Targeting Rules, % rules) can be visible to your users.
Expand Down

0 comments on commit 8fba4e8

Please sign in to comment.