Skip to content

Commit

Permalink
Merge pull request #19 from AAkira/dev/0.0.7
Browse files Browse the repository at this point in the history
Release 0.0.7
  • Loading branch information
AAkira authored Jul 28, 2019
2 parents a4d6e1d + e784c20 commit ced3a0e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class Sample {
suspend fun suspendHello(): String {
Napier.i("Hello")

runBlocking {
delay(3000L)
}
delay(3000L)

Napier.w("Napier!")

Expand Down Expand Up @@ -104,6 +102,9 @@ uses the `print`
```gradle
dependencies {
implementation "com.github.aakira:napier-ios:$napierVersion"
// arm
implementation 'com.github.aakira:napier-iosArm32:$napierVersion'
implementation 'com.github.aakira:napier-iosArm64:$napierVersion'
}
```

Expand Down Expand Up @@ -186,6 +187,12 @@ fun debugBuild() {
NapierProxyKt.debugBuild()
```

### Clear antilog

```kotlin
Napier.takeLogalitm()
```

## Log level

| Platform | Sample |
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.40'
ext.kotlin_version = '1.3.41'

repositories {
google()
Expand All @@ -10,7 +10,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0-beta04'
classpath 'com.android.tools.build:gradle:3.5.0-beta05'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_version"

Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
// This library version
LIBRARY_VERSION_CODE = 6
LIBRARY_VERSION_NAME = "0.0.6"
LIBRARY_VERSION_CODE = 7
LIBRARY_VERSION_NAME = "0.0.7"

// android
mobileVersionCode = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class Sample {
suspend fun suspendHello(): String {
Napier.i("Hello")

runBlocking {
delay(3000L)
}
delay(3000L)

Napier.w("Napier!")

Expand All @@ -27,7 +25,7 @@ class Sample {
fun handleError() {
try {
throw Exception("throw error")
} catch(e: Exception) {
} catch (e: Exception) {
Napier.e("Napier Error", e)
}
}
Expand Down
31 changes: 22 additions & 9 deletions napier/src/commonMain/kotlin/com/github/aakira/napier/Napier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Napier {
baseArray.add(antilog)
}

fun isEnable(priority: Napier.Level, tag: String?) = baseArray.any { it.isEnable(priority, tag) }
fun isEnable(priority: Level, tag: String?) = baseArray.any { it.isEnable(priority, tag) }

@PublishedApi
internal fun rawLog(priority: Level, tag: String?, throwable: Throwable?, message: String?) {
Expand All @@ -31,47 +31,47 @@ object Napier {
log(Level.VERBOSE, tag, throwable, message)
}

fun v(message: ()->String, throwable: Throwable? = null, tag: String? = null) {
fun v(message: () -> String, throwable: Throwable? = null, tag: String? = null) {
log(Level.VERBOSE, tag, throwable, message)
}

fun i(message: String, throwable: Throwable? = null, tag: String? = null) {
log(Level.INFO, tag, throwable, message)
}

fun i(message: ()->String, throwable: Throwable? = null, tag: String? = null) {
fun i(message: () -> String, throwable: Throwable? = null, tag: String? = null) {
log(Level.INFO, tag, throwable, message)
}

fun d(message: String, throwable: Throwable? = null, tag: String? = null) {
log(Level.DEBUG, tag, throwable, message)
}

fun d(message: ()->String, throwable: Throwable? = null, tag: String? = null) {
fun d(message: () -> String, throwable: Throwable? = null, tag: String? = null) {
log(Level.DEBUG, tag, throwable, message)
}

fun w(message: String, throwable: Throwable? = null, tag: String? = null) {
log(Level.WARNING, tag, throwable, message)
}

fun w(message: ()->String, throwable: Throwable? = null, tag: String? = null) {
fun w(message: () -> String, throwable: Throwable? = null, tag: String? = null) {
log(Level.WARNING, tag, throwable, message)
}

fun e(message: String, throwable: Throwable? = null, tag: String? = null) {
log(Level.ERROR, tag, throwable, message)
}

fun e(message: ()->String, throwable: Throwable? = null, tag: String? = null) {
fun e(message: () -> String, throwable: Throwable? = null, tag: String? = null) {
log(Level.ERROR, tag, throwable, message)
}

fun wtf(message: String, throwable: Throwable? = null, tag: String? = null) {
log(Level.ASSERT, tag, throwable, message)
}

fun wtf(message: ()->String, throwable: Throwable? = null, tag: String? = null) {
fun wtf(message: () -> String, throwable: Throwable? = null, tag: String? = null) {
log(Level.ASSERT, tag, throwable, message)
}

Expand All @@ -81,10 +81,23 @@ object Napier {
}
}

fun log(priority: Level, tag: String? = null, throwable: Throwable? = null, message: ()->String) {
fun log(priority: Level, tag: String? = null, throwable: Throwable? = null, message: () -> String) {
if (isEnable(priority, tag)) {
rawLog(priority, tag, throwable, message())
}
}
}

/**
* Remove antilog from the base array.
*/
fun takeLogalitm(antilog: Antilog) {
baseArray.remove(antilog)
}

/**
* Clear all antilogs from the base array.
*/
fun takeLogalitm() {
baseArray.clear()
}
}

0 comments on commit ced3a0e

Please sign in to comment.