Giter VIP home page Giter VIP logo

wood's Introduction

Wood

codecov

What is this library about?

Wood is a simple in-app Timber log recorder. Wood records and persists all Timber log into Room Database , and provides a UI for reviewing their content.

Features

  1. Apps using Wood will display a notification showing a summary of ongoing Timber log activity. Tapping on the notification launches the full Wood UI. Apps can optionally suppress the notification, and launch the Wood UI directly from within their own interface. Log can be copied into clipboard or exported via a share intent.
  2. Search Log by any keyword.
  3. The main Wood activity is launched in its own task, allowing it to be displayed alongside the host app UI using Android 7.x multi-window support.

Wood requires Android 4.1+ and Timber.

Warning: The data generated and stored when using this Timber logger may contain sensitive information such as tokens or password. It is intended for use during development, and not in release builds or other production deployments.

Setup

Download

Based on your IDE you can import library in one of the following ways

Gradle:

1, Add JitPack at your root level build.gradle file.

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

//com.github.UsherAndroid:external

2, Add the dependency in your build.gradle file. Add it alongside the no-op variant to isolate Wood from release builds as follows:

debugImplementation 'com.github.TonyTangAndroid.Wood:wood:0.9.9.1'
releaseImplementation 'com.github.TonyTangAndroid.Wood:wood-no-op:0.9.9.1'

If you want this in library in both release and compile, then try this :

implementation 'com.github.TonyTangAndroid.Wood:wood:0.9.9.1'

Usage

In your application code, create an instance of WoodTree and add it as an Timber tree when planting your Timber tree:

package com.tonytangandroid.wood.sample

import android.app.Application
import android.util.Log
import com.tonytangandroid.wood.WoodTree
import timber.log.Timber

object WoodIntegrationUtil {

  @JvmStatic
  fun initWood(application: Application) {
    Timber.plant(
      WoodTree(application)
        .retainDataFor(WoodTree.Period.FOREVER)
        .logLevel(Log.VERBOSE)
        .autoScroll(false)
        .maxLength(100000)
        .showNotification(true)
    )
  }
}

That's it! Wood will now record all Timber log.

Show Sticky/Normal Notification

Sticky => true and Normal => false

new WoodTree(context).showNotification(true/false)

Other Settings

Check stored data

Launch the Wood UI directly within your app with the intent from Wood.getLaunchIntent().

startActivity(Wood.getLaunchIntent(this));
Add app shortcut to your app
Wood.addAppShortcut(this);
Max Length

Set Response Max length to store

new WoodTree(context).maxContentLength(10240L)//the maximum length (in bytes)
Retention Period

Set the retention period for Timber log data captured

new WoodTree(context).retainDataFor(Period.ONE_WEEK)

Acknowledgements

Gander (parent repo)

  • Gander - Copyright Ashok Varma, Inc.
Thanks to Ashok Varma for his amazing library Gander. This repo is inspired from Gander at the very beginning.

Wood uses the following open source libraries:

  • Timber - Copyright Jake Wharton.

License

Copyright (C) 2019 Tony Tang.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

wood's People

Contributors

ashok-varma avatar jbeguna04 avatar shanmugasanthosh7 avatar tonytangandroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wood's Issues

Targeting API 31 while running on API 31 crashes

If you target API 31 and then run on an API 31 (Android 12) device, you will get the following error:

    java.lang.IllegalArgumentException: xxxx: 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.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
        at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
        at android.app.PendingIntent.getActivity(PendingIntent.java:444)
        at android.app.PendingIntent.getActivity(PendingIntent.java:408)
        at com.tonytangandroid.wood.NotificationHelper.show(NotificationHelper.java:62)
        at com.tonytangandroid.wood.WoodTree.create(WoodTree.java:184)
        at com.tonytangandroid.wood.WoodTree.doLog(WoodTree.java:176)
        at com.tonytangandroid.wood.WoodTree.access$000(WoodTree.java:18)
        at com.tonytangandroid.wood.WoodTree$1.run(WoodTree.java:133)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)

I believe this function in NotificationHelper.java needs updating:

    public synchronized void show(Leaf transaction, boolean stickyNotification) {
        addToBuffer(transaction);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, CHANNEL_ID)
                .setContentIntent(PendingIntent.getActivity(mContext, 0, Wood.getLaunchIntent(mContext), 0))
                .setLocalOnly(true)
                .setSmallIcon(R.drawable.wood_icon)
                .setColor(ContextCompat.getColor(mContext, R.color.wood_colorPrimary))
                .setOngoing(stickyNotification)
                .setContentTitle(mContext.getString(R.string.wood_notification_title));
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        int count = 0;
        for (int i = TRANSACTION_BUFFER.size() - 1; i >= 0; i--) {
            if (count < BUFFER_SIZE) {
                if (count == 0) {
                    builder.setContentText(getNotificationText(TRANSACTION_BUFFER.valueAt(i)));
                }
                inboxStyle.addLine(getNotificationText(TRANSACTION_BUFFER.valueAt(i)));
            }
            count++;
        }
        builder.setAutoCancel(true);
        builder.setStyle(inboxStyle);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            builder.setSubText(String.valueOf(TRANSACTION_COUNT));
        } else {
            builder.setNumber(TRANSACTION_COUNT);
        }
        builder.addAction(getDismissAction());
        builder.addAction(getClearAction());
        mNotificationManager.notify(CHANNEL_ID.hashCode(), builder.build());
    }
    

Share whole log

Very nice library

Is it possible to share whole log not just a record?

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.