-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: use custom logger class (#577)
## 📜 Description Use own `Logger` class in Android. ## 💡 Motivation and Context Using own logger instance has many advantages: - we can implement internal implementation (like turn on/turn off logger depending on certain conditions); - we can change internals and forward logs to react-native js side if needed; - since it's our implementation we can change internals as we want and don't change the functionality in every piece of the code; - we can apply various optimization technique later on (such as inline functions etc.). So in this PR I'm introducing own `Logger` class and use it everywhere in the code. The main advantage of this class is that it's active only in debug mode and in release mode it will not send any logs (thus it'll slightly improve performance) and will not reveal details about the libraries that are used internally n the particular application. Later on I may add even more optimizations, such as inline functions etc. Closes #576 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### Android - added `Logger` class; - use `Logger` everywhere as alternative to `Log`. ## 🤔 How Has This Been Tested? <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> <!-- see how your change affects other areas of the code, etc. --> ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<img width="1202" alt="image" src="https://github.com/user-attachments/assets/a1f735b7-a6b0-422d-88d6-ee433c815d30">|<img width="1910" alt="image" src="https://github.com/user-attachments/assets/016f89f7-f6eb-4e5f-9137-9761b70df15b">| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
- Loading branch information
1 parent
961e8a1
commit 7c9c450
Showing
8 changed files
with
40 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
20 changes: 20 additions & 0 deletions
20
android/src/main/java/com/reactnativekeyboardcontroller/log/Logger.kt
This file contains 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,20 @@ | ||
package com.reactnativekeyboardcontroller.log | ||
|
||
import android.util.Log | ||
import com.reactnativekeyboardcontroller.BuildConfig | ||
|
||
object Logger { | ||
private val enabled = BuildConfig.DEBUG | ||
|
||
fun i(tag: String?, message: String, throwable: Throwable? = null) { | ||
if (enabled) { | ||
Log.i(tag, message, throwable) | ||
} | ||
} | ||
|
||
fun w(tag: String?, message: String, throwable: Throwable? = null) { | ||
if (enabled) { | ||
Log.w(tag, message, throwable) | ||
} | ||
} | ||
} |
This file contains 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 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 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