The Android Arsenal – Logging

⚠️ Error Tracing is FUN! ⚠️


Documentation

Set up

Step 1. Add the JitPack repository to your construct file .

    allprojects {
        repositories {
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency.

    dependencies {
            implementation 'com.github.rommansabbir:TraceX:Tag'
    }

Model out there

Why TraceX?

TraceX is designed to observe all Uncaught Exception happens in app lifecycle by default. Additionally, shopper can disable auto monitoring Uncaught Exception by following the TraceXConfig and manually register an Exercise for monitoring by calling TraceX.registerActivity API.

TraceX will robotically write a log to the app cache listing if the Uncaught Exception is an occasion of RuntimeException based mostly on Config. Consumer may also write a brand new log the the app cache listing by calling TraceX.writeANewLog API.

Additionally, shopper can get all logs written by TraceX or shopper itself by calling TraceX.writeANewLog API.

Consumer may also take away a listing of managed or unmanaged logs from the cache listing that’s written by TraceX. Or, merely take away all logs from cache listing written by TraceX.

Motto of this library:

As a developer we do not know on which machine or on which constraint system will throw Exception or RuntimeException if the applying is in PRODUCTION. If any Uncaught Exception happens throughout app lifecycle we get to find out about it by way of others Logging library.

However, as a developer you would possibly need to know navigate the consumer to a particular web page (eg. residence web page) when an deadly exception happens which finally kill the applying course of within the machine. Earlier than that web page navigation, we are able to write a log to the app cache listing by following the present System Data, Present Thread, Throwable that occurred and a JSON object as more information. Or just, we are able to write our personal log to the cache listing at our personal.

In order that, we are able to get the record written logs from the cache listing when consumer run the applying once more, we are able to course of the logs, like SEND IT TO THE REMOTE SERVER for bug fixing, analytics or just ignore or take away the log from the cache listing.

NOTE: Writing or Studying logs from cache listing follows Encryption/Decryption course of by utilizing StoreX.


initialize and Entry?:

Initialize TraceX out of your Software.onCreate()

    TraceXProvider.register(TraceXConfig(this,
        autoRegisterForEachActivity = true,
        autoLogRuntimeExceptions = true
    ))

To Entry TraceX name TraceXProvider.INSTANCE which return an occasion of TraceX

Public APIs:

  • registerListener(listener: TraceXCallback?), To register or unregister listener

  • registerActivity(exercise: Exercise?): Boolean, Manually register an actvity for Uncaught Error Occasion Hanlding and return Boolean. Additionally, TraceXConfig.autoRegisterForEachActivity ought to be false

  • writeANewLog(throwable: Throwable, additionalInfo: String = ""): Boolean, To jot down a brand new encrypted log to the app cache listing and return Boolean.

  • getRecentCrashLogs(): MutableList<TraceXCrashLog>, To get record of current logs from app cache listing. [Note: It’s a CPU Intensive process, execute the operation with Coroutine/RxJava.]

  • clearCrashLogs(record: MutableList<TraceXCrashLog>), To take away a given record of TraceXCrashLog from the app cache listing. [Note: It’s a CPU Intensive process, execute the operation with Coroutine/RxJava.]

  • clearAllLogs(): Boolean, To take away all logs from the app cache listing written by **TraceX [Note: It’s a CPU Intensive process, execute the operation with Coroutine/RxJava.]


Remeber: All public APIs will throw TraceXNotInitializedException if TraceX just isn’t initialized earlier than accessing it is APIs.


Checkout the pattern app for the implementaion intimately


Completely happy Coding….


Contact me

LinkedIn | Weblog


License

Apache Model 2.0

Copyright (C) 2022 Romman Sabbir

Licensed beneath the Apache License, Model 2.0 (the "License");
you might not use this file besides in compliance with the License.
You might acquire a replica of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Until required by relevant legislation or agreed to in writing, software program
distributed beneath the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, both categorical or implied.
See the License for the precise language governing permissions and
limitations beneath the License.

Source_link

Leave a Reply

Your email address will not be published.