Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Oct 21, 2020
1 parent 844ac7f commit 84ef6fd
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 22 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,27 @@ dependencies {
// ALTERNATIVELY you can add ALL modules at once like following
// implementation 'com.github.MFlisar:Lumberjack:<LATEST-VERSION>'
// Wrapper for java => will provide a class `L2` with all the functions from `L` but without the inlining feature because this is not possible in java
// can be used to use Lumberjack in mixed java and kotlin projects
// implementation 'com.github.MFlisar.Lumberjack:lumberjack-java-wrapper:<LATEST-VERSION>'
}
```

### Usage

Once in your app do following:

```kotlin
// simply console logger
L.plant(ConsoleTree())
// a file logger (optional)
val fileLoggingSetup = FileLoggingSetup(context) // default setup keeps log files for 7 days and creates a new file each day
L.plant(FileLoggingTree(fileLoggingSetup))
// if desired, disable all logging in release
// L.enabled = Build.DEBUG
```

### Example - LOGGING

The logger is simply used like following:
Expand All @@ -47,8 +65,8 @@ L.d { "Simpe log" }
// simply log with custom tag
L.tag("CUSTOM-TAG").d { "Some message with a tag" }
// Log and only run log code based on a function / boolean flag
L.logIf { true }.d { "Is logged, as flag is true" }
L.logIf { someFunction() }.d { "Is logged and only executed if someFunction returns true" }
L.logIf { true }?.d { "Is logged, as flag is true" }
L.logIf { someFunction() }?.d { "Is logged and only executed if someFunction returns true" }
```

If used with `logIf` the expression is only executed if `logIf` returns true so it's save to keep all the logging lines in production code.
Expand All @@ -73,18 +91,4 @@ If used with `logIf` the expression is only executed if `logIf` returns true so
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
```

### Usage

Once in your app do following:

```kotlin
// simply console logger
L.plant(ConsoleTree())
// a file logger
val fileLoggingSetup = FileLoggingSetup(context) // default setup keeps log files for 7 days and creates a new file each day
L.plant(FileLoggingTree(fileLoggingSetup))
// if desired, disable all logging in release
// L.enabled = Build.DEBUG
```
1 change: 1 addition & 0 deletions library-java-wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
45 changes: 45 additions & 0 deletions library-java-wrapper/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.github.MFlisar'

android {

compileSdkVersion setup.compileSdk

defaultConfig {
minSdkVersion setup.minSdk
targetSdkVersion setup.targetSdk
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

// ------------------------
// Kotlin
// ------------------------

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlinVersion}"

// ------------------------
// Library
// ------------------------

implementation project(':lumberjack-library')

// ------------------------
// Others
// ------------------------

api "com.jakewharton.timber:timber:${versions.timber}"
}
17 changes: 17 additions & 0 deletions library-java-wrapper/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in M:\SWDevelopment\AndroidSDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interfaces
# class:
#-keepclassmembers class fqcn.of.javascript.interfaces.for.webview {
# public *;
#}
5 changes: 5 additions & 0 deletions library-java-wrapper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.michaelflisar.lumberjack.java">


</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.michaelflisar.lumberjack

import com.michaelflisar.lumberjack.data.StackData
import timber.log.Timber

/*
Expand All @@ -16,7 +17,7 @@ object L2 {

@JvmStatic
fun callStackCorrection(value: Int): L2 {
L.setCallStackCorrection(value)
L.callStackCorrection(value)
return L2
}

Expand Down Expand Up @@ -113,8 +114,9 @@ object L2 {

fun log(logBlock: () -> Unit) {
if (L.enabled && Timber.treeCount() > 0) {
L.setCallStackCorrection(4)
logBlock()
L.callStackCorrection(4)
if (L.packageNameFilter?.let { it.invoke(StackData.create(0).className) } != false)
logBlock()
}
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/com/michaelflisar/lumberjack/L.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object L {
/*
* provide a filter for stacks - you will get the full stack trace package name
*/
var packageNameFilter: ((String) -> Boolean)? = null
var packageNameFilter: ((packageName: String) -> Boolean)? = null

// --------------
// special functions
Expand Down Expand Up @@ -107,7 +107,7 @@ object L {
@PublishedApi
internal inline fun log(logBlock: () -> Unit) {
if (enabled && Timber.treeCount() > 0) {
if (packageNameFilter?.let { it.invoke(StackData.create(0).getStackTag()) } != false)
if (packageNameFilter?.let { it.invoke(StackData.create(0).className) } != false)
logBlock()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.regex.Pattern


class StackData(
private val className: String,
val className: String,
private val simpleFileName: String,
private val methodName: String,
private val line: Int
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ include ':lumberjack-library'
project(':lumberjack-library').projectDir = new File(settingsDir, 'library')
include ':lumberjack-filelogger'
project(':lumberjack-filelogger').projectDir = new File(settingsDir, 'library-filelogger')

include ':lumberjack-java-wrapper'
project(':lumberjack-java-wrapper').projectDir = new File(settingsDir, 'library-java-wrapper')

0 comments on commit 84ef6fd

Please sign in to comment.