Code Monkey home page Code Monkey logo

methlog's Introduction

MethLog

MethLog is an annotation based method call logging plugin for observing completion time.
Annotation is processed & transformed only in debuggable builds.

You just need to add @MethLog above any of your function & that's it!
You'll see the calculated time in your Logcat with Class & Method Name.

This project uses HunterDebug as a base, but only logs the completion time of annotated methods.
MethLog does not log annotated method's parameters & return values like HunterDebug or Hugo.

Adding MethLog in your project

In your project's root build.gradle

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.lazygeniouz.methlog:methlog-plugin:1.3.2'
        // the plugin also adds the dependency for @MethLog annotation internally, 
        // so that you don't have to add it to every one of your project's build.gradle.
    }
}

then in your app or library's build.gradle:

apply plugin: 'com.android.application'
// or 'com.android.library' in case of a library
apply plugin: 'com.lazygeniouz.methlog'

You can enable & disable MethLog by adding the following:

methLog {
    enabled true | false
    // May require a clean / rebuild.
}

Using @MethLog

Simply annotate any function with @MethLog & it should work fine.

Example

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    logMessageWithDelay("MethLog says Hi!")
    logMessageWithDelay("MethLog says Hi, again!")
}

@MethLog
private fun logMessageWithDelay(message: String) {
    Thread.sleep(2000)
    logDebug(message)
}

Output:

I/MethLog: ⇢ MainActivity.logMessageWithDelay() completed in 2000ms.
I/MethLog: ⇢ MainActivity.logMessageWithDelay() completed in 2001ms.

Issues & Suggestions

This is my first Gradle Plugin 😄,
so if you see anything wrong in the code base or something that can be improved then do let me know along with an appropriate implementation (if you happen to know) & I'll try to incorporate those changes.

Create a new issue if you face any problem or have any suggestions.
I'll appreciate if you create a PR as well (if possible).

Finally, don't forget to ⭐️ the library! :)

methlog's People

Contributors

itznotabug avatar

Stargazers

 avatar

Watchers

 avatar

methlog's Issues

Project.afterEvaluate() + Extension Issue.

The extension method is suitable to toggle the transform process, however, the current implementation seems to be broken with respect to using the above mentioned.
Even though the updated value of variable enabled is reflected in the Project.afterEvaluate() closure, the same also breaks the Transform process when using BaseExtension.registerTransform().

It either works on default settings when running for the first time or completely stops the transform process.
A better choice is to get the created extension & check the enabled status in the MethLogTransform.transform() method.

Debuggable builds only.

Would be better to make the library target the debuggable builds only.
Keeping annotations can be fine & simply don't process the bytecode transform in non-debuggable builds.

Just like what Hugo does.

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.