GithubHelp home page GithubHelp logo

qase / kotlinlogger Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 3.0 629 KB

Smart android logger in kotlin.

Home Page: http://www.quanti.cz

License: MIT License

Kotlin 92.58% CMake 1.61% C++ 5.81%
kotlin kotlin-library android android-library logging logger quanti qase

kotlinlogger's Introduction

Release Build Status codebeat badge API License: MIT Maintainer: kidal5 Qase: KotlinLogger

KotlinLogger

Smart android logger written in Kotlin language.

Mostly used in Prague based android develpoment company - Quanti for everything. Product is still being actively developed.

Features

  • Usable in every JVM language including Java/Kotlin/Scala ...
  • Very easy to use
  • No more TAGs, but you can still use them
  • Easy to extend using your own ILogger interface
  • Lot of optional parameters
  • Lightweight
  • Possibility to print system info
  • Send data to Qase LoggingServer
  • Every logged exception is logged to own separate file
  • Sample app is ready to build

Installation

Click HERE.

Code example

Usage is simple

  1. Make sure you have set your applicationId in gradle
android{
  defaultConfig{
    applicationId = "your.cool.app"
    ...
  }
  ...
}
  1. Initialise Log and add all needed loggers. Every logger can be initialized using bundle or use default values.
// Log initialisation
Log.initialise(context)

//forwards all log to android logcat
val androidBundle = LoggerBundle(LogLevel.INFO)
Log.addLogger(AndroidLogger(androidBundle))

//default log level is warn
//apply plugins google-services and firebase.crashlytics, copy google-services.json in app/ directory
//download google-services.json from https://console.firebase.google.com/u/0/project/{project_id}/settings/general/android:{project_package}
//add these two lines in app/build.gradle
//  apply plugin: 'com.google.gms.google-services'
//  apply plugin: 'com.google.firebase.crashlytics'
Log.addLogger(CrashlyticsLogger())

//Every LogBundles has ton of options, see javadoc for more
//DayLogBundle logs every day to one separate log file
val dayLogBundle = DayLogBundle(maxDaysSaved = 4)
Log.addLogger(FileLogger(applicationContext, dayLogBundle))

//CircleLogBundle logs to one file until specified size is reached, but may overflow
val rotateBundle = CircleLogBundle(numOfFiles = 7)
Log.addLogger(FileLogger(applicationContext, rotateBundle))

//StrictCircleLogBundle logs to one file until specified size is reached, never overflows but slower
val strictRotateBundle = StrictCircleLogBundle(maxFileSizeMegaBytes = 1)  
Log.addLogger(FileLogger(applicationContext, strictRotateBundle))

//WebLogger logs to Qase LogServer using REST API or WebSockets
//Run your own server and then debug your application remotely
val restBundle = RestLoggerBundle("http://webserver/api/v1/")
val webSocketBundle = WebSocketLoggerBundle("ws://webserver/ws/v1/")
Log.addLogger(WebLogger(choose restBundle or webSocketBundle))
  1. Then log as you would normally do - just using another dependency (or log sync using Log.xSync methods)
Log.v("This");
Log.d("is");
Log.i("sample");
Log.i("text", "OWN TAG");
Log.i("that");
Log.i("will");
Log.iSync("be");
Log.w("logged.");
Log.e("wi", Exception()); //throwable
  1. Other possibilities
//Enable unchecked crash handling
Log.useUncheckedErrorHandler()

//Delete all logs
FileLogger.deleteAllLogs()

//Print system logs
Log.logMetadata(appContext)

//Use of SendLogDialogFragment
//It can send zip of logs to email or save to sd card 
//WRITE_EXTERNAL_STORAGE permission is needed if you want to save logs to sd card
SendLogDialogFragment.newInstance("[email protected]", deleteLogs = true).show(supportFragmentManager, "TAG")

License

MIT

kotlinlogger's People

Contributors

anezkaquanti avatar balakzde avatar havlisimo avatar kidal5 avatar neubami94 avatar petrposvic avatar ruzicka1911 avatar zelenmi6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kotlinlogger's Issues

Add function to remove logger

It would be nice if I could define logger id in the constructor of Logger and be able to remove logger specified by the id.

Use case:
In debug version of my app I am using optional web logging (if user specifies url of his logging server and turns web logging on). He should also be able to turn the logging off, but I am not able to turn it off in current state.

getZipOfLogs can delete files in app files directory

getZipOfLogs deletes all files older than specified date including files created outside logger (e.g. by the application). It is needed to be very careful while deleting files as it may cause user data loss or other critical problems.
Please check also other parts of the library so this cannot happen

Add function to save logs to SD Card

At the moment, the only way to save logs is via SendLogDialogFragment, which forces user interaction.
It would be nice to have a function to save logs without the need of this.

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.