Git Product home page Git Product logo

rxlogs's Introduction

RxLogs Advanced Logging

Android Arsenal

PLog and DataLog (Loggers)

A file based advanced logging framework written in Kotlin.

Overview

PLogs provides quick & simple file logging solution. All logs are saved to files in storage path provided. These logs are helpful when developer wants to analyze user activities within the app. A new log file is created every hour on a user event. These logs can be filtered and sorted easily. Logs can easily be exported as zip file base on filter type. This zip file can be uploaded to server on export. PLogs also provide functionality to arrange data logs into a predefined directory structure. These logs can be used for a specific events within the app. Logs can be saved as encrypted data.

Alt text Image1 Image2

Read more about RxLogs usage on this Medium article:

Sending logs from apps in real-time using ELK stack & MQTT

Features

  1. Logs events in files created separately every hour with 'PLogs' logger. (24 hours)
  2. Files can be compressed and exported for time and day filters
  3. Clear Logs easily
  4. Save logs to app's storage path
  5. Export Logs to custom path as zip file
  6. RxJava2 support
  7. Custom Log formatting
  8. CSV support
  9. Custom timestamps support
  10. Custom data logging support with 'DataLogs' logger.
  11. Encryption support added
  12. Auto Log system crashes
  13. Multiple directory structures
  14. Print logs as String
  15. Export all or single types of logs
  16. XML configuration support for internal persistence
  17. Logger events Subscription
  18. Advanced Automation for deleting logs automatically
  19. Exports HTML formatted exceptions
  20. ELK Stack Supported See more about it here.
  21. MQTT Support
  22. Added logs queueing for offline support (MQTT Feature)

Setup

Add module to your project:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

    dependencies {
    implementation 'com.github.umair13adil:RxLogs:[Latest_Version]'
    }

Usage

Add following implementation in your Application class.

class MainApplication : Application() {
    
        override fun onCreate() {
            super.onCreate()
    
            setUpPLogger() //Initialize PLogger here
        }

private fun setUpPLogger() {
             val logsPath = "PLogs"
             
                     val logsConfig = LogsConfig(
                             isDebuggable = true,
                             savePath = logsPath,
                             zipFileName = "MyLogs",
                             exportPath = logsPath + File.separator + "PLogsOutput"
                     )

                     PLog.applyConfigurations(logsConfig, saveToFile = true, context = context) //Initialize configurations
                   
         }
}

Where are my logs stored?


Your logs can be found in the path of your app's directory in storage:

--> Android/data/[YOUR_APP_PACKAGE]/files/[YOUR_LOGS_FOLDER_NAME]/Logs/

Image3

To Log data to file simply call like this


1. Simple Info Log

    PLog.logThis(TAG, "method_name", "Log: " + Math.random(), LogLevel.INFO)

2. Simple Warning Log

    PLog.logThis(TAG, "method_name", "This is a warning message!", LogLevel.WARNING)

3. Error Log

    PLog.logThis(TAG, "method_name", "This is a error message!", LogLevel.ERROR)

4. Severe Log

    PLog.logThis(TAG, "method_name", "This is a severe error message!", LogLevel.SEVERE)

5. Exception Log

    PLog.logThis(TAG, "reportError", Exception("This is an Exception!"))

6. Throwable Log

    PLog.logThis(TAG, "reportError", Throwable("This is an Throwable!"))

7. Exception Log with Info

    PLog.logThis(TAG, "reportError", info = "Some Info", exception = Exception("This is an Exception!"), level =  LogLevel.ERROR)

8. Throwable Log with Info

    PLog.logThis(TAG, "reportError", info = "Some Info", throwable = Throwable("This is an Exception!"), level =  LogLevel.SEVERE)

ELK Elastic Stack Support


To configure set this flag to true:

    PLogMetaInfoProvider.elkStackSupported = true

Send additional Meta info for better filtering at LogStash dashboard. This has to be set once on application start.

    PLogMetaInfoProvider.setMetaInfo(MetaInfo(
                /**App**/
                appId = BuildConfig.APPLICATION_ID,
                appName = getString(R.string.app_name),
                appVersion = BuildConfig.VERSION_NAME,
                language = "en-US",

                /**Environment**/
                environmentId = BuildConfig.APPLICATION_ID,
                environmentName = BuildConfig.BUILD_TYPE,

                /**Organization**/
                organizationId = "9975",
                organizationUnitId = "24",
                organizationName = "BlackBox",

                /**User**/
                userId = "12112",
                userName = "Umair",
                userEmail = "[email protected]",
                deviceId = "12",

                /**Device**/
                deviceSerial = "SK-78",
                deviceBrand = Build.BRAND,
                deviceName = Build.DEVICE,
                deviceManufacturer = Build.MANUFACTURER,
                deviceModel = Build.MODEL,
                deviceSdkInt = Build.VERSION.SDK_INT.toString(),
                batteryPercent = "87",

                /**Location**/
                latitude = 0.0,
                longitude = 0.0,

                /**Labels**/
                labels = hashMapOf(Pair("env", "dev"))
        ))

Enable MQTT Feature


Note: PLogger currently supports SSL connection for MQTT.

Step 1:

Add certificate in your app's raw resource directory.

Step 2:

Add following block for initializing MQTT logging.

        PLogMQTTProvider.initMQTTClient(applicationContext,
                topic = "YOUR_TOPIC",
                brokerUrl = "YOUR_URL", //Without Scheme
                certificateRes = R.raw.m2mqtt_ca,
                clientId = "5aa39cef4d544d658ecaf23db701099c",
                writeLogsToLocalStorage = true,
                initialDelaySecondsForPublishing = 30,
                debug = true
        )

That's it, MQTT setup is done.


ProGuard Rules:

-keep class com.blackbox.plog.pLogs.models.** { ; } -keepclassmembers class com.blackbox.plog.pLogs.models.* { ; } -keep class com.blackbox.plog.* {; } -keep class com.blackbox.plog.pLogs.exporter.formatter.** {; } -keep class com.blackbox.plog.pLogs.exporter.** {*; }

Wiki

Checkout Wiki for more information.

Change Log

Version: 1.0.9
  • Changed parameter name in LogsConfig from "enabled" to "enableLogsWriteToFile"
Version: 1.0.3
  • Added MQTT Logging support
Version: 1.0.2
  • Added ELK Logstash JSON logging support
Version: 0.23
  • Added functionality to write logs in background thread.
  • Fixed zip issues.
  • Fixed issues with data formatting on decryption of text files.
Version: 0.21
  • Removed 'context' parameter in logs configuration
  • Added 'exportFormatted' parameter in logs configuration to enable 'HTML formatted Logs in case of exceptions'
Version: 0.17
  • 'autoClearLogs' parameter in logs configuration changed to 'autoDeleteZipOnExport'
  • Added 'autoClearLogs' parameter in logs configuration to enable/disable 'Auto Clear Logs' feature
  • Added 'context' parameter in logs configuration to enable 'HTML formatted Logs in case of exceptions'
  • Added 'Log Events' for formatted exceptions output
    • EventTypes.NEW_ERROR_REPORTED_FORMATTED
    • EventTypes.SEVERE_ERROR_REPORTED_FORMATTED
  • Changed 'type: LogLevel' parameter in 'logThis()' function to 'level: LogLevel'

MIT License

Copyright (c) 2018 Muhammad Umair Adil

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rxlogs's People

Contributors

umair13adil avatar wasimshigri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rxlogs's Issues

Provide a snippet to export logs correctly

I have been using this library in my Kotlin application, I want those logs to be exported. Can you please show be the correct way to use exportAllDataLogs() function to export it into zip. I see that the function is of type Observable, a guidance for such method invocation would be helpful, thanks!!

Targeting S+

Hi,

I got this error when I add RxLogs dependency :
Process: amf.ambadge.debug, PID: 30075
java.lang.IllegalArgumentException: amf.ambadge.debug: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

Did you planned to correct it ?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.