Skip to content

Commit

Permalink
Misc (#122)
Browse files Browse the repository at this point in the history
* Update dependencies and use dexcount

* Add should log extender

* Allow null message

* Add nullable eThro

* Update changelog
  • Loading branch information
AllanWang authored Dec 31, 2017
1 parent 7a9ca23 commit 332d633
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
6 changes: 6 additions & 0 deletions android-lib.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.getkeepsafe.dexcount'
group = project.APP_GROUP

android {
Expand All @@ -27,6 +28,11 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}

buildTypes {
release {
minifyEnabled false
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${KOTLIN}"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.github.triplet.gradle:play-publisher:1.2.0'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ca.allanwang.kau.logging

import ca.allanwang.kau.BuildConfig

/**
* Created by Allan Wang on 2017-06-19.
*/
object KL : KauLogger("KAU")
object KL : KauLogger("KAU", { BuildConfig.DEBUG })
41 changes: 26 additions & 15 deletions core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import android.util.Log
* if (BuildConfig.DEBUG) d(message)
* }
*/
open class KauLogger(val tag: String) {
open class KauLogger(
/**
* Tag to be used for each log
*/
val tag: String,
/**
* Toggle to dictate whether a message should be logged
*/
var shouldLog: (priority: Int) -> Boolean = { true }) {

/**
* Global toggle to enable the whole logger
*/
open var enabled = true

inline fun v(message: () -> Any?) = log(Log.VERBOSE, message)

Expand All @@ -37,20 +41,22 @@ open class KauLogger(val tag: String) {

inline fun e(t: Throwable? = null, message: () -> Any?) = log(Log.ERROR, message, t)

inline fun eThrow(message: Any) = with(message.toString()) {
log(Log.ERROR, { this }, Throwable(this))
inline fun eThrow(message: Any?) {
val msg = message?.toString() ?: return
log(Log.ERROR, { msg }, Throwable(msg))
}

inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) {
if (enabled)
logImpl(priority, message()?.toString() ?: "null", t)
if (shouldLog(priority))
logImpl(priority, message()?.toString(), t)
}

open fun logImpl(priority: Int, message: String, t: Throwable?) {
open fun logImpl(priority: Int, message: String?, t: Throwable?) {
val msg = message ?: "null"
if (t != null)
Log.e(tag, message, t)
Log.e(tag, msg, t)
else
Log.println(priority, tag, message)
Log.println(priority, tag, msg)
}

/**
Expand Down Expand Up @@ -82,12 +88,17 @@ class KauLoggerExtension(val tag: String, val logger: KauLogger) {

inline fun e(t: Throwable? = null, message: () -> Any?) = log(Log.ERROR, message, t)

inline fun eThrow(message: Any) = with(message.toString()) {
log(Log.ERROR, { this }, Throwable(this))
inline fun eThrow(message: Any?) {
val msg = message?.toString() ?: return
log(Log.ERROR, { msg }, Throwable(msg))
}

inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) =
logger.log(priority, { "$tag: ${message()?.toString() ?: "null"}" }, t)
logger.log(priority, {
val msg = message()?.toString()
if (msg == null) null
else "$tag: $msg"
}, t)

inline fun checkThread(id: Int) {
d {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ ABOUT_LIBRARIES=6.0.1
ANKO=0.10.3
BLURRY=2.1.1
CONSTRAINT_LAYOUT=1.1.0-beta4
FAST_ADAPTER=3.0.4
FAST_ADAPTER_COMMONS=3.0.3
FAST_ADAPTER=3.0.5
FAST_ADAPTER_COMMONS=3.0.5
GLIDE=4.4.0
ICONICS=3.0.0
IICON_GOOGLE=3.0.1.2
Expand Down
1 change: 0 additions & 1 deletion mediapicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies {
implementation project(':adapter')

api "com.github.bumptech.glide:glide:${GLIDE}"
kapt "com.github.bumptech.glide:compiler:${GLIDE}"
implementation "jp.wasabeef:blurry:${BLURRY}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ca.allanwang.kau.logging.KL
class SampleApp : Application() {
override fun onCreate() {
super.onCreate()
KL.enabled = BuildConfig.DEBUG
KPrefSample.initialize(this, "pref_sample")
}
}
1 change: 1 addition & 0 deletions sample/src/main/res/xml/kau_changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<version title="v3.6.1" />
<item text=":core: [Breaking] Removed private text field and introduced lazy logging functions" />
<item text=":adapter: Improve library item layout" />

<version title="v3.6.0" />
<item text=":adapter: Create withOnRepeatedClickListener" />
Expand Down

0 comments on commit 332d633

Please sign in to comment.