-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
158 additions
and
122 deletions.
There are no files selected for viewing
13 changes: 7 additions & 6 deletions
13
demo/app/src/main/java/com/michaelflisar/lumberjack/demo/JavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
package com.michaelflisar.lumberjack.demo; | ||
|
||
import com.michaelflisar.lumberjack.L; | ||
import com.michaelflisar.lumberjack.L2; | ||
|
||
public class JavaTest | ||
{ | ||
public static void test() | ||
{ | ||
L.d(new Throwable()); | ||
// USE L2 in JAVA code, otherwise callstack won't be correct because of missing inlining functionality in java! | ||
L2.d(new Throwable(), "JAVA 1 - ERROR"); | ||
|
||
L.d("JAVA 1 - Test message"); | ||
L.d("JAVA 2 - Test message with arg: %d", 500); | ||
L.e(new Throwable("ERROR"), "JAVA 3 - Test error"); | ||
L2.d("JAVA 2 - Test message"); | ||
L2.d("JAVA 3 - Test message with arg: %d", 500); | ||
L2.e(new Throwable("ERROR"), "JAVA 4 - Test error"); | ||
|
||
L.tag("CUSTOM-TAG").d("JAVA 4 - Test message with custom tag"); | ||
L2.tag("CUSTOM-TAG").d("JAVA 5 - Test message with custom tag"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
library/src/main/java/com/michaelflisar/lumberjack/L2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.michaelflisar.lumberjack | ||
|
||
import timber.log.BaseTree | ||
import timber.log.Timber | ||
|
||
/* | ||
this class is meant for usage in JAVA only, as functions can't be inlined there | ||
and the callstack index to find the interesting callers class is different because of not inlining the functions! | ||
*/ | ||
object L2 { | ||
|
||
@JvmStatic | ||
fun tag(tag: String): L2 { | ||
Timber.tag(tag) | ||
return L2 | ||
} | ||
|
||
@JvmStatic | ||
fun v(t: Throwable?) = L2.log { Timber.v(t) } | ||
|
||
@JvmStatic | ||
fun v(t: Throwable? = null, message: String, vararg args: Any) = L2.log { Timber.v(t, message, *args) } | ||
|
||
@JvmStatic | ||
fun v(message: String, vararg args: Any) = L2.log { Timber.v(message, *args) } | ||
|
||
@JvmStatic | ||
fun v(message: String) = L2.log { Timber.v(message) } | ||
|
||
@JvmStatic | ||
fun d(t: Throwable?) = L2.log { Timber.d(t) } | ||
|
||
@JvmStatic | ||
fun d(t: Throwable? = null, message: String, vararg args: Any) = L2.log { Timber.d(t, message, *args) } | ||
|
||
@JvmStatic | ||
fun d(t: Throwable? = null, message: String) = L2.log { Timber.d(t, message) } | ||
|
||
@JvmStatic | ||
fun d(message: String, vararg args: Any) = L2.log { Timber.d(message, *args) } | ||
|
||
@JvmStatic | ||
fun d(message: String) = L2.log { Timber.d(message) } | ||
|
||
@JvmStatic | ||
fun i(t: Throwable?) = L2.log { Timber.i(t) } | ||
|
||
@JvmStatic | ||
fun i(t: Throwable? = null, message: String, vararg args: Any) = L2.log { Timber.i(t, message, *args) } | ||
|
||
@JvmStatic | ||
fun i(t: Throwable? = null, message: String) = L2.log { Timber.i(t, message) } | ||
|
||
@JvmStatic | ||
fun i(message: String, vararg args: Any) = L2.log { Timber.i(message, *args) } | ||
|
||
@JvmStatic | ||
fun i(message: String) = L2.log { Timber.i(message) } | ||
|
||
@JvmStatic | ||
fun w(t: Throwable?) = L2.log { Timber.w(t) } | ||
|
||
@JvmStatic | ||
fun w(t: Throwable? = null, message: String, vararg args: Any) = L2.log { Timber.w(t, message, *args) } | ||
|
||
@JvmStatic | ||
fun w(t: Throwable? = null, message: String) = L2.log { Timber.w(t, message) } | ||
|
||
@JvmStatic | ||
fun w(message: String, vararg args: Any) = L2.log { Timber.w(message, *args) } | ||
|
||
@JvmStatic | ||
fun w(message: String) = L2.log { Timber.w(message) } | ||
|
||
@JvmStatic | ||
fun e(t: Throwable?) = L2.log { Timber.e(t) } | ||
|
||
@JvmStatic | ||
fun e(t: Throwable? = null, message: String, vararg args: Any) = L2.log { Timber.e(t, message, *args) } | ||
|
||
@JvmStatic | ||
fun e(t: Throwable? = null, message: String) = L2.log { Timber.e(t, message) } | ||
|
||
@JvmStatic | ||
fun e(message: String, vararg args: Any) = L2.log { Timber.e(message, *args) } | ||
|
||
@JvmStatic | ||
fun e(message: String) = L2.log { Timber.e(message) } | ||
|
||
@JvmStatic | ||
fun wtf(t: Throwable?) = L2.log { Timber.wtf(t) } | ||
|
||
@JvmStatic | ||
fun wtf(t: Throwable? = null, message: String, vararg args: Any) = L2.log { Timber.wtf(t, message, *args) } | ||
|
||
@JvmStatic | ||
fun wtf(t: Throwable? = null, message: String) = L2.log { Timber.wtf(t, message) } | ||
|
||
@JvmStatic | ||
fun wtf(message: String, vararg args: Any) = L2.log { Timber.wtf(message, *args) } | ||
|
||
@JvmStatic | ||
fun wtf(message: String) = L2.log { Timber.wtf(message) } | ||
|
||
// -------------- | ||
// helper function | ||
// -------------- | ||
|
||
fun log(logBlock: () -> Unit) { | ||
if (L.enabled && Timber.treeCount() > 0) { | ||
setCallStackCorrection(4) | ||
logBlock() | ||
} | ||
} | ||
|
||
private fun setCallStackCorrection(correction: Int) { | ||
val forest = Timber.forest() | ||
var i = 0 | ||
for (tree in forest) { | ||
if (tree is BaseTree) { | ||
tree.setCallStackCorrection(correction) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters