Giter Club home page Giter Club logo

chesire / lifecyklelog Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 4.0 396 KB

Android library to log out Activity and Fragment lifecycle methods

License: Apache License 2.0

Kotlin 92.68% Java 3.59% Ruby 3.73%
android android-library android-architecture android-logging android-lifecycle kotlin kotlin-android fragment-lifecycle activity-lifecycle android-fragments android-activity android-activity-lifecycle lifecycle-methods annotation hacktoberfest

lifecyklelog's Introduction

LifecykleLog

Library to easily log out Android lifecycle methods for Activities and Fragments.

Android Arsenal Android CI codecov

Installation

Gradle: Make sure you have JitPack as a source

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

add the following line to your build.gradle, with version being the latest tag.

implementation 'com.github.chesire:lifecyklelog:{version}'

Usage example

Initialize in your application class.

class ApplicationOverride : Application() {
    override fun onCreate() {
        super.onCreate()
        LifecykleLog.initialize(this)
    }
}

Add the @LogLifecykle annotation to the Activity or Fragment that the lifecycle methods should be logged for.

@LogLifecykle
class MainActivity : AppCompatActivity() { ...

@LogLifecykle
class MainFragment : Fragment() { ...

Then lifecycle events will be logged out in logcat.

D/Lifecykle: MainActivity ⇀ onStart
D/Lifecykle: MainFragment ⇀ onAttach
D/Lifecykle: MainFragment ⇀ onCreate
D/Lifecykle: MainFragment ⇀ onCreateView
D/Lifecykle: MainFragment ⇀ onActivityCreated
D/Lifecykle: MainFragment ⇀ onStart
D/Lifecykle: MainActivity ⇀ onResume
D/Lifecykle: MainFragment ⇀ onResume
D/Lifecykle: MainActivity ⇀ onPause
D/Lifecykle: MainFragment ⇀ onPause
D/Lifecykle: MainActivity ⇀ onStop
D/Lifecykle: MainFragment ⇀ onStop

Configuration

Logging mechanism

By default LogLifecykle will output to Log.d with a tag of Lifecykle, to override this behaviour pass an implementation into the LifecykleLog.logHandler.

LifecykleLog.logHandler = LogHandler { clazz, lifecycleEvent, bundle ->
    Log.e(clazz, lifecycleEvent) 
}

This can allow you to use other logging frameworks such as Timber.

LifecykleLog.logHandler = LogHandler { clazz, lifecycleEvent, bundle ->
    Timber.i("$clazz -> $lifecycleEvent - $bundle")
}

For lifecycle methods which pass a bundle along, it will automatically be pushed through the LogHandler. In instances where there is no bundle, or it is empty, then the value will simply be "null".

Lifecycle methods

To customise which lifecycle methods are logged out, an array of the LifecycleEvent enum can be passed into LifecykleLog.logEvents, this can also be done with the @LogLifecykle annotation.

LifecykleLog.logEvents = arrayOf(
    LifecycleEvent.ON_CREATE, 
    LifecycleEvent.ON_DESTROY
)

@LogLifecykle(overrideLogEvents = [LifecycleEvent.ON_START])
class MainActivity : AppCompatActivity() {

@LogLifecykle(overrideLogEvents = [LifecycleEvent.ON_ACTIVITY_CREATED, LifecycleEvent.ON_ATTACH])
class MainFragment : Fragment() {

If logEvents is provided to the LifecykleLog then it will override the defaults.
If overrideLogEvents is provided on the annotation, only the methods that are provided in this will be logged out.

Class name

To customise the class name that is logged out, a new name can be provided to the annotation.

@LogLifecykle(className = "MainActivity")
class MainActivity : AppCompatActivity() {

@LogLifecykle(className = "MaybeMainFragment")
class MainFragment : Fragment() {

This can be useful if ProGuard strips out the class names and you really need to see them in the logs. By default the name will be pulled from the objects class.java.simpleName.

Remove Annotation

If you want to perform logging of ALL Activities and Fragments, without needing to add the annotation to them, then the configuration option requireAnnotation can be set to false.

LifecykleLog.requireAnnotation = false

This will ignore any annotations that are currently set, and perform logging for every Activity and Fragment on the lifecycle events defined in LifecykleLog.logEvents.

For more examples and usage, please refer to the sample.

Contributing

Please read CONTRIBUTING.md for details on how to contribute.

License

Apache 2.0 - See LICENSE for more information.

lifecyklelog's People

Contributors

chesire avatar dependabot-preview[bot] avatar dependabot[bot] avatar imgbot[bot] avatar shaunplummer avatar

Stargazers

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

Watchers

 avatar  avatar

lifecyklelog's Issues

Upload to Maven

Need to upload the library to Maven.
Add the badge to the README for which version is available.

Update Detekt to latest

Detekt version should be bumped up to RC-15, as this fixes an issue with running it on Windows.
Along with this the detekt rules should be updated.

Allow adding extra data to the annotation

See if there is some way to add extra data to the annotation, I doubt there is much that can be added manually, but maybe just some extra string or constants etc will be the limit

Tcdjzjgyx

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the youtxkgxkgxglh you'd like
A clear and concise description of what you want to happen.
YouTube. Com is great

Allow configuration outside of the initialize block

Is your feature request related to a problem? Please describe.
The configuration can only be performed when calling initialize, meaning this cannot be changed later on and also makes calling from Java cumbersome.
Describe the solution you'd like
Ideally it should have some configuration methods, so after calling initialize the other methods can be called afterwards (or rely on sensible defaults).

Add support for AboutLibraries

Is your feature request related to a problem? Please describe.
AboutLibraries is a popular library to list all OpenSource libraries used in a project, this repo should contain a file containing the required strings for it.

Describe the solution you'd like
Add an xml file containing the library information that would be used, example:

<resources>
    <string name="define_lifecyklelog" translatable="false">year;owner</string>
    <!-- Author section -->
    <string name="library_lifecyklelog_author" translatable="false">Chesire</string>
    <string name="library_lifecyklelog_authorWebsite" translatable="false">https://github.com/Chesire</string>
    <!-- Library section -->
    <string name="library_lifecyklelog_libraryName" translatable="false">LifecykleLog</string>
    <string name="library_lifecyklelog_libraryDescription" translatable="false">Library to easily log out Android lifecycle methods for Activities and Fragments.</string>
    <string name="library_lifecyklelog_libraryWebsite" translatable="false">https://github.com/Chesire/LifecykleLog</string>
    <string name="library_lifecyklelog_libraryVersion" translatable="false">2.0.0</string>
    <!-- OpenSource section -->
    <string name="library_lifecyklelog_isOpenSource" translatable="false">true</string>
    <string name="library_lifecyklelog_repositoryLink" translatable="false">https://github.com/Chesire/LifecykleLog</string>
    <!-- ClassPath for autoDetect section -->
    <string name="library_lifecyklelog_classPath" translatable="false">com.chesire.lifecyklelog</string>
    <!-- License section -->
    <string name="library_lifecyklelog_licenseId" translatable="false">mit</string>
    <!-- Custom variables section -->
    <string name="library_lifecyklelog_year" translatable="false">2019</string>
    <string name="library_lifecyklelog_owner" translatable="false">Chesire</string>
</resources>

Build on Bitrise

Set up the project to build on bitrise.
Once setup add the build tag to the README.

Bitrise should run all static analysis, and should build the library independant from the samples.

Update README

Update the README to mention how to use the project

Add in code coverage reporting

Now that there are some unit tests for the library, it's probably worth making sure the coverage is up to scratch, and plus side can add another badge.
Need to add support for JaCoCo and CodeCov.

Add documentation for adding from Jitpack

Is your feature request related to a problem? Please describe.
Currently there is only documentation for adding from Bintray, the README should specify how to add from Jitpack as well.

Add detekt

Add detekt to the project.
Update the rules so that it includes public tasks need documentation

Log out service lifecycle

Not sure if this is possible by just subscribing to some lifecycle methods somewhere, but would be good to be able to get when services start up/shut down.

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.