-
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.
- Fixed bug with long android messages leveraging the wrong tag instance - Improved test coverage - Updated dependencies
- Loading branch information
1 parent
ee225a7
commit dd3282a
Showing
17 changed files
with
256 additions
and
195 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
32 changes: 32 additions & 0 deletions
32
common/android/src/androidMain/kotlin/com/toxicbakery/logging/LogCatDelegate.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,32 @@ | ||
package com.toxicbakery.logging | ||
|
||
import android.util.Log | ||
|
||
/** | ||
* Default Android delegate for logging. | ||
*/ | ||
object LogCatDelegate : LogDelegate { | ||
|
||
override fun writeLog(level: Int, tag: String, msg: String) { | ||
when (level) { | ||
Arbor.DEBUG -> Log.d(tag, msg) | ||
Arbor.ERROR -> Log.e(tag, msg) | ||
Arbor.INFO -> Log.i(tag, msg) | ||
Arbor.VERBOSE -> Log.v(tag, msg) | ||
Arbor.WARNING -> Log.w(tag, msg) | ||
Arbor.WTF -> Log.wtf(tag, msg) | ||
} | ||
} | ||
|
||
override fun writeLog(level: Int, tag: String, msg: String, throwable: Throwable) { | ||
when (level) { | ||
Arbor.DEBUG -> Log.d(tag, msg, throwable) | ||
Arbor.ERROR -> Log.e(tag, msg, throwable) | ||
Arbor.INFO -> Log.i(tag, msg, throwable) | ||
Arbor.VERBOSE -> Log.v(tag, msg, throwable) | ||
Arbor.WARNING -> Log.w(tag, msg, throwable) | ||
Arbor.WTF -> Log.wtf(tag, msg, throwable) | ||
} | ||
} | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
common/android/src/androidMain/kotlin/com/toxicbakery/logging/LogDelegate.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,18 @@ | ||
package com.toxicbakery.logging | ||
|
||
/** | ||
* Delegate for printing Android logs. This is useful for injecting a new output such as to a file. | ||
*/ | ||
interface LogDelegate { | ||
|
||
/** | ||
* Write a log with a given level, tag, and message. | ||
*/ | ||
fun writeLog(level: Int, tag: String, msg: String) | ||
|
||
/** | ||
* Write a log with a given level, tag, message, and a printed throwable exception. | ||
*/ | ||
fun writeLog(level: Int, tag: String, msg: String, throwable: Throwable) | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
common/android/src/androidTest/kotlin/com/toxicbakery/logging/LogCatDelegateTest.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,34 @@ | ||
package com.toxicbakery.logging | ||
|
||
import org.junit.Test | ||
|
||
class LogCatDelegateTest { | ||
|
||
@Test | ||
fun writeLog() { | ||
LogCatDelegate.writeLog(Arbor.DEBUG, "tag", "msg") | ||
LogCatDelegate.writeLog(Arbor.ERROR, "tag", "msg") | ||
LogCatDelegate.writeLog(Arbor.INFO, "tag", "msg") | ||
LogCatDelegate.writeLog(Arbor.VERBOSE, "tag", "msg") | ||
LogCatDelegate.writeLog(Arbor.WARNING, "tag", "msg") | ||
LogCatDelegate.writeLog(Arbor.WTF, "tag", "msg") | ||
|
||
LogCatDelegate.writeLog(Arbor.DEBUG, "tag", "msg", Exception()) | ||
LogCatDelegate.writeLog(Arbor.ERROR, "tag", "msg", Exception()) | ||
LogCatDelegate.writeLog(Arbor.INFO, "tag", "msg", Exception()) | ||
LogCatDelegate.writeLog(Arbor.VERBOSE, "tag", "msg", Exception()) | ||
LogCatDelegate.writeLog(Arbor.WARNING, "tag", "msg", Exception()) | ||
LogCatDelegate.writeLog(Arbor.WTF, "tag", "msg", Exception()) | ||
} | ||
|
||
@Test | ||
fun invalidLevel_withoutException() { | ||
LogCatDelegate.writeLog(0, "tag", "msg") | ||
} | ||
|
||
@Test | ||
fun invalidLevel_withException() { | ||
LogCatDelegate.writeLog(0, "tag", "msg", Exception()) | ||
} | ||
|
||
} |
Oops, something went wrong.