/Logger-Android

Android Library for easing logging and to store loges in Files

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Logger

GitHub issues GitHub last commit GitHub issues GitHub pull requests

FeaturesDevelopmentUsageLicenseContribution


ezgif-com-video-to-gif.gif

Android Library for easing logging and to store loges in Files

Features

  • Written in Kotlin
  • No boilerplate code
  • Easy initialization

Gradle Dependency

  • Add the JitPack repository to your project's build.gradle file
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Add the dependency in your app's build.gradle file
dependencies {
    implementation 'com.github.akshaaatt:Logger-Android:1.0.0'
}

Development

  • Prerequisite: Latest version of the Android Studio and SDKs on your pc.
  • Clone this repository.
  • Use the gradlew build command to build the project directly or use the IDE to run the project to your phone or the emulator.

Usage

Init:

val config = Config.Builder(it.path)
    .setDefaultTag("TAG")
    .setLogcatEnable(true)
    .setDataFormatterPattern("dd-MM-yyyy-HH:mm:ss")
    .setStartupData(
        mapOf(
            "App Version" to "${BuildConfig.VERSION}",
            "Device Application Id" to BuildConfig.APPLICATION_ID,
            "Device Version Code" to BuildConfig.VERSION_CODE.toString(),
            "Device Version Name" to BuildConfig.VERSION_NAME,
            "Device Build Type" to BuildConfig.BUILD_TYPE,
            "Device" to Build.DEVICE,
            "Device SDK" to Build.VERSION.SDK_INT.toString(),
            "Device Manufacturer" to Build.MANUFACTURER
        )
    ).build()

Logger.init(config)

Log:

Logger.i("TAG", "This is normal Log with custom TAG")
Logger.i(msg = "This is normal Info Log")
Logger.d(msg = "This is normal Debug Log")
Logger.w(msg = "This is normal Warning Log")
Logger.e(msg = "This is normal Error Log")

Exception:

try {
    //...
} catch (e: Exception) {
    Logger.e(msg = "log message", throwable = e)
}

Compress to Zip file and Email logs:

Logger.apply {
    compressLogsInZipFile { zipFile ->
        zipFile?.let {
            FileIntent.fromFile(
                this@MainActivity,
                it,
                BuildConfig.APPLICATION_ID
            )?.let { intent ->
                intent.putExtra(Intent.EXTRA_SUBJECT, "Log File")
                try {
                    startActivity(Intent.createChooser(intent, "Email logs..."))
                } catch (e: java.lang.Exception) {
                    e(throwable = e)
                }
            }
        }
    }
}

for share file with email or etc add this provider in the AndroidManifest.xml file:

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>
</provider>

And this one in resource/xml/provider_paths:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path name="media" path="."/>
</paths>

Delete log files:

Logger.deleteFiles()

Enable and disable logging:

Logger.setEnable(boolean)

Inspired by

License

This Project is licensed under the GPL version 3 or later.

Contribution

You are most welcome to contribute to this project!