Suppose an error occurs while executing a code. We must display messages on the console to understand what the compiler is doing in the backend. ![]() The console is the system’s monitor connected with an input device. Kotlin Print to Console in Android Studio.It can be named as LogUtils.kt and you just need to paste the below code. And also we don’t need logs in Release mode, it is also taken care of.įirst of all, you need to create one file in your utils package. ![]() In this article, we will do a better approach to logging without using any external library, and calling the log method will be easy. And there are some libraries that solve this problem of adding TAG in the tag method. For a point being, you can put TAG in the top of the class as const val TAG = "MyApp", yet you need to mention it in every class or you have to add it in Utils.kt. The problem with the above approach is every time you write a log there is the requirement of TAG, it becomes annoying at some point. This usually appears in red color in red color in Logcat window in the Android studio. These levels areįor example, if we want to show log in Logcat, then we need to call, Log.e(TAG, "message), in this case, we want to show an error. Log the class provides 5 priorities level to filter out code according to our requirements. While building Android apps, we as Android developers put a lot of logs into our code. It displays messages in real-time and keeps a history so you can view older messages. The Logs will appear in Logcat window in Android Studio displays system messages, such as when a garbage collection occurs, and messages that you added to your app with the Log class. Pic Credit: by Andrea Piacquadio What is Logging?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |