-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bolteu/v.1.0.3
V.1.0.3
- Loading branch information
Showing
10 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
kalev-android/src/main/java/eu/bolt/kalev/AndroidFastLog.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,25 @@ | ||
package eu.bolt.kalev | ||
|
||
import android.util.Log | ||
import eu.bolt.kalev.fast.FastLog | ||
import eu.bolt.kalev.utils.generateTag | ||
|
||
class AndroidFastLog : FastLog { | ||
|
||
private val stackDepth = 3 | ||
|
||
override fun v(message: String, tag: String?) { | ||
val finalTag = tag ?: generateTag(stackDepth) | ||
Log.v(finalTag, message) | ||
} | ||
|
||
override fun d(message: String, tag: String?) { | ||
val finalTag = tag ?: generateTag(stackDepth) | ||
Log.d(finalTag, message) | ||
} | ||
|
||
override fun i(message: String, tag: String?) { | ||
val finalTag = tag ?: generateTag(stackDepth) | ||
Log.i(finalTag, message) | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
kalev-android/src/main/java/eu/bolt/kalev/utils/TagGenerator.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,24 @@ | ||
package eu.bolt.kalev.utils | ||
|
||
import android.os.Build | ||
import java.util.regex.Pattern | ||
|
||
private val anonymousClassPattern = Pattern.compile("(\\$\\d+)+$") | ||
private const val maxTagLength = 23 | ||
|
||
internal fun generateTag(stackDepth: Int): String { | ||
val stackTrace = Throwable().stackTrace | ||
check(stackTrace.size > stackDepth) { "Synthetic stacktrace didn't have enough elements: are you using proguard?" } | ||
val element = stackTrace[stackDepth] | ||
|
||
var tag = element.className | ||
val matcher = anonymousClassPattern.matcher(tag) | ||
if (matcher.find()) { | ||
tag = matcher.replaceAll("") | ||
} | ||
tag = tag.substring(tag.lastIndexOf('.') + 1) | ||
// Tag length limit was removed in API 24. | ||
return if (tag.length <= maxTagLength || Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
tag | ||
} else tag.substring(0, maxTagLength) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package eu.bolt.kalev.fast | ||
|
||
interface FastLog { | ||
|
||
fun v(message: String, tag: String? = null) | ||
|
||
fun d(message: String, tag: String? = null) | ||
|
||
fun i(message: String, tag: String? = null) | ||
} |
27 changes: 27 additions & 0 deletions
27
kalev-lib/src/main/java/eu/bolt/kalev/fast/SystemFastLog.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,27 @@ | ||
package eu.bolt.kalev.fast | ||
|
||
/** | ||
* Default [FastLog] implementation which prints the logs to standard output | ||
*/ | ||
class SystemFastLog : FastLog { | ||
|
||
override fun v(message: String, tag: String?) { | ||
print(message, tag) | ||
} | ||
|
||
override fun d(message: String, tag: String?) { | ||
print(message, tag) | ||
} | ||
|
||
override fun i(message: String, tag: String?) { | ||
print(message, tag) | ||
} | ||
|
||
private fun print(message: String, tag: String?) { | ||
if (tag == null) { | ||
println(message) | ||
} else { | ||
println(StringBuilder(tag).append(": ").append(message).toString()) | ||
} | ||
} | ||
} |
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