diff --git a/README.md b/README.md index d06eace..f8c0def 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,27 @@ dependencies { // ALTERNATIVELY you can add ALL modules at once like following // implementation 'com.github.MFlisar:Lumberjack:' + + // 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:' } ``` +### 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: @@ -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. @@ -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 ``` \ No newline at end of file diff --git a/library-java-wrapper/.gitignore b/library-java-wrapper/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/library-java-wrapper/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library-java-wrapper/build.gradle b/library-java-wrapper/build.gradle new file mode 100644 index 0000000..3f7b1f5 --- /dev/null +++ b/library-java-wrapper/build.gradle @@ -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}" +} diff --git a/library-java-wrapper/proguard-rules.pro b/library-java-wrapper/proguard-rules.pro new file mode 100644 index 0000000..04825f7 --- /dev/null +++ b/library-java-wrapper/proguard-rules.pro @@ -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 *; +#} diff --git a/library-java-wrapper/src/main/AndroidManifest.xml b/library-java-wrapper/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d0d5602 --- /dev/null +++ b/library-java-wrapper/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + diff --git a/library/src/main/java/com/michaelflisar/lumberjack/L2.kt b/library-java-wrapper/src/main/java/com/michaelflisar/lumberjack/L2.kt similarity index 93% rename from library/src/main/java/com/michaelflisar/lumberjack/L2.kt rename to library-java-wrapper/src/main/java/com/michaelflisar/lumberjack/L2.kt index bc45aa8..b0fb74a 100644 --- a/library/src/main/java/com/michaelflisar/lumberjack/L2.kt +++ b/library-java-wrapper/src/main/java/com/michaelflisar/lumberjack/L2.kt @@ -1,5 +1,6 @@ package com.michaelflisar.lumberjack +import com.michaelflisar.lumberjack.data.StackData import timber.log.Timber /* @@ -16,7 +17,7 @@ object L2 { @JvmStatic fun callStackCorrection(value: Int): L2 { - L.setCallStackCorrection(value) + L.callStackCorrection(value) return L2 } @@ -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() } } } diff --git a/library/src/main/java/com/michaelflisar/lumberjack/L.kt b/library/src/main/java/com/michaelflisar/lumberjack/L.kt index 426d9c0..b2935d8 100644 --- a/library/src/main/java/com/michaelflisar/lumberjack/L.kt +++ b/library/src/main/java/com/michaelflisar/lumberjack/L.kt @@ -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 @@ -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() } } diff --git a/library/src/main/java/com/michaelflisar/lumberjack/data/StackData.kt b/library/src/main/java/com/michaelflisar/lumberjack/data/StackData.kt index 3245f20..5dd82ee 100644 --- a/library/src/main/java/com/michaelflisar/lumberjack/data/StackData.kt +++ b/library/src/main/java/com/michaelflisar/lumberjack/data/StackData.kt @@ -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 diff --git a/settings.gradle b/settings.gradle index b17123b..6975204 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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')