-
Notifications
You must be signed in to change notification settings - Fork 4
[FSSDK-11985] feat: add android logger support #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b70cc9e
chore: add new classes for logging
muzahidul-opti 6620481
refactor: update log level conversion logic
muzahidul-opti d628732
refactor: optimize log level conversion
muzahidul-opti e1faba9
style: update logback configuration and log levels
muzahidul-opti b604613
fix: ensure debugging logs are only printed in debug mode
muzahidul-opti 9326b6b
chore: update logback.xml
muzahidul-opti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1 @@ | ||
| <configuration | ||
| xmlns="https://tony19.github.io/logback-android/xml" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="https://tony19.github.io/logback-android/xml https://cdn.jsdelivr.net/gh/tony19/logback-android/logback.xsd" | ||
| > | ||
| <appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender"> | ||
| <tagEncoder> | ||
| <pattern>Optimizely</pattern> | ||
| </tagEncoder> | ||
| <encoder> | ||
| <pattern>%msg</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <root level="DEBUG"> | ||
| <appender-ref ref="logcat" /> | ||
| </root> | ||
| </configuration> | ||
| <!-- We do not use this since all logging is handled programmatically via FlutterLogbackAppender and forwarded to the Dart logger. --> |
62 changes: 62 additions & 0 deletions
62
android/src/main/java/com/optimizely/optimizely_flutter_sdk/FlutterLogbackAppender.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.optimizely.optimizely_flutter_sdk; | ||
| import com.optimizely.optimizely_flutter_sdk.helper_classes.Constants; | ||
|
|
||
| import android.os.Handler; | ||
| import android.os.Looper; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import ch.qos.logback.classic.spi.ILoggingEvent; | ||
| import ch.qos.logback.core.AppenderBase; | ||
| import io.flutter.plugin.common.MethodChannel; | ||
|
|
||
| public class FlutterLogbackAppender extends AppenderBase<ILoggingEvent> { | ||
|
|
||
| public static final String CHANNEL_NAME = "optimizely_flutter_sdk_logger"; | ||
| public static MethodChannel channel; | ||
| private static final Handler mainThreadHandler = new Handler(Looper.getMainLooper()); | ||
|
|
||
| public static void setChannel(MethodChannel channel) { | ||
| FlutterLogbackAppender.channel = channel; | ||
| } | ||
|
|
||
| @Override | ||
| protected void append(ILoggingEvent event) { | ||
| if (channel == null) { | ||
| return; | ||
| } | ||
|
|
||
| String message = event.getFormattedMessage(); | ||
| String level = event.getLevel().toString(); | ||
| int logLevel = convertLogLevel(level); | ||
| Map<String, Object> logData = new HashMap<>(); | ||
| logData.put("level", logLevel); | ||
| logData.put("message", message); | ||
|
|
||
| mainThreadHandler.post(() -> { | ||
| if (channel != null) { | ||
| channel.invokeMethod("log", logData); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| int convertLogLevel(String logLevel) { | ||
| if (logLevel == null || logLevel.isEmpty()) { | ||
| return 3; | ||
| } | ||
|
|
||
| switch (logLevel.toUpperCase()) { | ||
| case "ERROR": | ||
| return 1; | ||
| case "WARN": | ||
| return 2; | ||
| case "INFO": | ||
| return 3; | ||
| case "DEBUG": | ||
| return 4; | ||
| default: | ||
| return 3; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.