Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,50 +59,49 @@ 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)
)
}
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
```java
new WoodTree(context).showNotification(true/false)
```kotlin
WoodTree(context).showNotification(true/false)
```

### Other Settings
##### Check stored data
Launch the Wood UI directly within your app with the intent from `Wood.getLaunchIntent()`.
```java
startActivity(Wood.getLaunchIntent(this));
```kotlin
startActivity(Wood.getLaunchIntent(this))
```

##### Add app shortcut to your app
```java
Wood.addAppShortcut(this);
```kotlin
Wood.addAppShortcut(this)
```

##### Max Length
Set Response Max length to store
```java
new WoodTree(context).maxContentLength(10240L)//the maximum length (in bytes)
```kotlin
WoodTree(context).maxContentLength(10240L)//the maximum length (in bytes)
```

##### Retention Period
Set the retention period for Timber log data captured
```java
new WoodTree(context).retainDataFor(Period.ONE_WEEK)
```kotlin
WoodTree(context).retainDataFor(Period.ONE_WEEK)
```

## Acknowledgements
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apply plugin: 'com.android.application'
apply plugin: "org.jetbrains.kotlin.android"

android {
namespace = "com.tonytangandroid.wood.sample"

buildTypes {
debug {
testCoverageEnabled true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package="com.tonytangandroid.wood.sample">

<application
android:name=".App"
android:name="com.tonytangandroid.wood.sample.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/java/com/tonytangandroid/wood/sample/App.java

This file was deleted.

14 changes: 14 additions & 0 deletions app/src/main/java/com/tonytangandroid/wood/sample/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tonytangandroid.wood.sample

import android.app.Application
import com.tonytangandroid.wood.sample.HomeActivity.Companion.logInBackground
import com.tonytangandroid.wood.sample.WoodIntegrationUtil.initWood

class App : Application() {

override fun onCreate() {
super.onCreate()
initWood(this)
logInBackground()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.tonytangandroid.wood.sample

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import timber.log.Timber

class GeneratingLogActivity : AppCompatActivity() {
private val handler = Handler(Looper.getMainLooper())
private var count = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_keep_generating_log)
}

override fun onResume() {
super.onResume()
generate()
}

private fun generate() {
handler.postDelayed(Runnable { this.log() }, 1000)
}

private fun log() {
(0..9).forEach { i ->
count++
Timber.v("generate log :%s", count)
}
generate()
}

override fun onPause() {
super.onPause()
stop()
}

private fun stop() {
handler.removeCallbacksAndMessages(null)
}
}

This file was deleted.

75 changes: 75 additions & 0 deletions app/src/main/java/com/tonytangandroid/wood/sample/HomeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.tonytangandroid.wood.sample

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.tonytangandroid.wood.Wood.addAppShortcut
import com.tonytangandroid.wood.Wood.getLaunchIntent
import timber.log.Timber
import java.lang.Exception

class HomeActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
findViewById<View>(R.id.btn_generate_log).setOnClickListener(View.OnClickListener { view: View -> generateTimberLog() })
findViewById<View>(R.id.btn_test_extreme_log).setOnClickListener(View.OnClickListener { view: View -> keepGenerateLog() })
findViewById<View>(R.id.launch_wood_directly).setOnClickListener(View.OnClickListener { view: View -> launchWoodDirectly() })
addAppShortcut(this)
}

private fun keepGenerateLog() {
startActivity(Intent(this, GeneratingLogActivity::class.java))
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.sample_menu, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == R.id.action_menu_github) {
val url = "https://github.com/TonyTangAndroid/Wood"
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(url)
startActivity(i)
return true
}
return super.onOptionsItemSelected(item)
}

private fun launchWoodDirectly() {
startActivity(getLaunchIntent(this))
}

private fun generateTimberLog() {
Timber.v("This is a VERBOSE message.")
Timber.d("This is an DEBUG message.")
Timber.i("This is an INFO message.")
Timber.w("This is an WARNING message.")
Timber.e("This is an ERROR message.")
logError()
}

private fun logError() {
try {
val shortSrc = ""
val substring = shortSrc.substring(10)
Timber.v("$substring$substring$substring")
} catch (e: Exception) {
Timber.e(e)
}
}

companion object {

fun logInBackground() {
Thread(Runnable { Timber.i("This is an INFO message triggered in background thread.") }).start()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import timber.log.Timber

object WoodIntegrationUtil {

@JvmStatic
fun initWood(application: Application) {
Timber.plant(
WoodTree(application,"tony")
WoodTree(application, "tony")
.retainDataFor(WoodTree.Period.FOREVER)
.logLevel(Log.VERBOSE)
.autoScroll(false)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_keep_generating_log.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:padding="16dp"
tools:context=".HomeActivity">

<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/wood_fragment"
android:name="com.tonytangandroid.wood.LeavesCollectionFragment"
android:layout_width="match_parent"
Expand Down
Loading