Skip to content

Commit

Permalink
Formatting fixes (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
findjigar authored Sep 20, 2023
1 parent d536d6f commit ae2b4e8
Show file tree
Hide file tree
Showing 70 changed files with 382 additions and 364 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ androidx-navigationUI = "2.7.2"
androidx-coordinatorLayout = "1.2.0"

android-gradle-plugin = "8.1.1"
android-test-runner="1.5.2"
android-test-runner = "1.5.2"

google-services = "4.3.15"

Expand Down Expand Up @@ -55,7 +55,7 @@ google-services = { module = "com.google.gms:google-services", version.ref = "go
crashkios-crashlytics = { module = "co.touchlab.crashkios:crashlytics", version.ref = "crashkios" }
crashkios-bugsnag = { module = "co.touchlab.crashkios:bugsnag", version.ref = "crashkios" }
bugsnag-android = { module = "com.bugsnag:bugsnag-android", version.ref = "bugsnag" }
stately-collections = { module = "co.touchlab:stately-collections", version.ref = "stately"}
stately-collections = { module = "co.touchlab:stately-collections", version.ref = "stately" }
testhelp = { module = "co.touchlab:testhelp", version.ref = "testhelp" }

koin = { module = "io.insert-koin:koin-core", version.ref = "koin-core" }
Expand Down
5 changes: 4 additions & 1 deletion kermit-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kotlin {
androidNativeArm64()
androidNativeX86()
androidNativeX64()

sourceSets {
val commonMain by getting
val commonTest by getting {
Expand Down Expand Up @@ -115,14 +115,17 @@ kotlin {
val linuxMain by getting
linuxMain
}

konanTarget.family == org.jetbrains.kotlin.konan.target.Family.MINGW -> {
val mingwMain by getting
mingwMain
}

konanTarget.family == org.jetbrains.kotlin.konan.target.Family.ANDROID -> {
val androidNativeMain by getting
androidNativeMain
}

else -> nativeMain
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ class LogcatWriter(private val messageStringFormatter: MessageStringFormatter =
override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
val formattedMessage = messageStringFormatter.formatMessage(null, null, Message(message))
try {
if(throwable == null){
when(severity){
if (throwable == null) {
when (severity) {
Severity.Verbose -> Log.v(tag, formattedMessage)
Severity.Debug -> Log.d(tag, formattedMessage)
Severity.Info -> Log.i(tag, formattedMessage)
Severity.Warn -> Log.w(tag, formattedMessage)
Severity.Error -> Log.e(tag, formattedMessage)
Severity.Assert -> Log.wtf(tag, formattedMessage)
}
}else{
when(severity){
} else {
when (severity) {
Severity.Verbose -> Log.v(tag, formattedMessage, throwable)
Severity.Debug -> Log.d(tag, formattedMessage, throwable)
Severity.Info -> Log.i(tag, formattedMessage, throwable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class LogcatLoggerTest {

ShadowLog.getLogs().apply {
assert(size > 0)
assertNotNull(find { it?.throwable?.message?.contains("Root Exception Message")?:false })
assertNotNull(find { it?.throwable?.cause?.message?.contains("Cause Exception Message")?:false })
assertNotNull(find { it?.throwable?.message?.contains("Root Exception Message") ?: false })
assertNotNull(find { it?.throwable?.cause?.message?.contains("Cause Exception Message") ?: false })
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

package co.touchlab.kermit

actual fun mutableLoggerConfigInit(logWriters: List<LogWriter>): MutableLoggerConfig = JvmMutableLoggerConfig(logWriters)
actual fun mutableLoggerConfigInit(logWriters: List<LogWriter>): MutableLoggerConfig =
JvmMutableLoggerConfig(logWriters)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LoggerFunctionsTest {

@Test
@Ignore
fun tagsWork(){
fun tagsWork() {
TODO()
/*val testLogWriter = getTestLogWriter()
Logger.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
@file:Suppress("NOTHING_TO_INLINE")

package co.touchlab.kermit

typealias MessageBlock = ()->String
typealias MessageBlock = () -> String

/**
* Base class for public Logger API. Extend to implement your own logger API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
package co.touchlab.kermit

@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
annotation class ExperimentalKermitApi()
annotation class ExperimentalKermitApi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package co.touchlab.kermit
* Called by Logger to actually send log statements to specific targets. There are several implementations provided by
* Kermit, but you can supply your own for specific use cases.
*/
abstract class LogWriter(){
abstract class LogWriter() {
open fun isLoggable(tag: String, severity: Severity): Boolean = true

abstract fun log(severity: Severity, message: String, tag: String, throwable: Throwable? = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface MessageStringFormatter {
fun formatTag(tag: Tag) = "(${tag.tag})"
fun formatMessage(severity: Severity?, tag: Tag?, message: Message): String {
// Optimize for Android
if(severity == null && tag == null)
if (severity == null && tag == null)
return message.message

val sb = StringBuilder()
Expand All @@ -35,7 +35,8 @@ interface MessageStringFormatter {
}

@JvmInline
value class Tag(val tag:String)
value class Tag(val tag: String)

@JvmInline
value class Message(val message: String)

Expand All @@ -46,20 +47,21 @@ value class Message(val message: String)
*
* "[severity: ][(tag) ][message]"
*/
object DefaultFormatter:MessageStringFormatter
object DefaultFormatter : MessageStringFormatter

/**
* Tags are a formal part of Android, but not other systems. This formatter omits them.
*/
object NoTagFormatter:MessageStringFormatter {
object NoTagFormatter : MessageStringFormatter {
override fun formatTag(tag: Tag): String = ""
override fun formatMessage(severity: Severity?, tag: Tag?, message: Message): String = super.formatMessage(severity, null, message)
override fun formatMessage(severity: Severity?, tag: Tag?, message: Message): String =
super.formatMessage(severity, null, message)
}

/**
* Just logs the message.
*/
object SimpleFormatter: MessageStringFormatter {
object SimpleFormatter : MessageStringFormatter {
override fun formatTag(tag: Tag): String = ""
override fun formatMessage(severity: Severity?, tag: Tag?, message: Message): String = message.message
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ interface MutableLoggerConfig : LoggerConfig {
}

expect fun mutableLoggerConfigInit(logWriters: List<LogWriter>): MutableLoggerConfig
fun mutableLoggerConfigInit(vararg logWriters: LogWriter, minSeverity: Severity = DEFAULT_MIN_SEVERITY):MutableLoggerConfig =
fun mutableLoggerConfigInit(
vararg logWriters: LogWriter,
minSeverity: Severity = DEFAULT_MIN_SEVERITY
): MutableLoggerConfig =
mutableLoggerConfigInit(logWriters.toList()).also { it.minSeverity = minSeverity }
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class LogFormatterTest {
}

@Test
fun noTag(){
fun noTag() {
assertEquals("Warn: Hello", NoTagFormatter.formatMessage(Severity.Warn, Tag("ATag"), Message("Hello")))
assertEquals("Hello", NoTagFormatter.formatMessage(null, Tag("ATag"), Message("Hello")))
}

@Test
fun simpleFormat(){
fun simpleFormat() {
assertEquals("Hello", SimpleFormatter.formatMessage(Severity.Warn, Tag("ATag"), Message("Hello")))
assertEquals("Hello", SimpleFormatter.formatMessage(null, Tag("ATag"), Message("Hello")))
assertEquals("Hello", SimpleFormatter.formatMessage(null, Tag(""), Message("Hello")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ open class OSLogWriter internal constructor(
private val darwinLogger: DarwinLogger
) : LogWriter() {

constructor(messageStringFormatter: MessageStringFormatter = DefaultFormatter) : this(messageStringFormatter, DarwinLoggerActual)
constructor(messageStringFormatter: MessageStringFormatter = DefaultFormatter) : this(
messageStringFormatter,
DarwinLoggerActual
)

override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
callLog(
Expand All @@ -52,7 +55,7 @@ open class OSLogWriter internal constructor(
}

@OptIn(ExperimentalNativeApi::class)
open fun logThrowable(osLogSeverity: UByte, throwable: Throwable){
open fun logThrowable(osLogSeverity: UByte, throwable: Throwable) {
darwinLogger.log(osLogSeverity, throwable.getStackTrace().joinToString("\n"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import kotlin.experimental.ExperimentalNativeApi
* Development-focused LogWriter. Will write a colored emoji according to Severity, and write the Throwable stack trace
* to println rather than oslog, as oslog will cut off long strings.
*/
open class XcodeSeverityWriter(private val messageStringFormatter: MessageStringFormatter = DefaultFormatter) : OSLogWriter(messageStringFormatter) {
open class XcodeSeverityWriter(private val messageStringFormatter: MessageStringFormatter = DefaultFormatter) :
OSLogWriter(messageStringFormatter) {
override fun formatMessage(severity: Severity, tag: Tag, message: Message): String =
"${emojiPrefix(severity)} ${messageStringFormatter.formatMessage(null, tag, message)}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

package co.touchlab.kermit

actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter = XcodeSeverityWriter(messageStringFormatter)
actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter =
XcodeSeverityWriter(messageStringFormatter)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class ConsoleWriter internal constructor(
private val messageStringFormatter: MessageStringFormatter,
private val console: ConsoleIntf
) : LogWriter() {
constructor(messageStringFormatter: MessageStringFormatter = DefaultFormatter) : this(messageStringFormatter, ConsoleActual)
constructor(messageStringFormatter: MessageStringFormatter = DefaultFormatter) : this(
messageStringFormatter,
ConsoleActual
)

override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
var output = messageStringFormatter.formatMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ConsoleWriterTest {

}

class ConsoleCollector: ConsoleIntf {
class ConsoleCollector : ConsoleIntf {
val errors = mutableListOf<String>()
val warnings = mutableListOf<String>()
val infos = mutableListOf<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

package co.touchlab.kermit

actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter = SystemWriter(messageStringFormatter)
actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter =
SystemWriter(messageStringFormatter)
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

package co.touchlab.kermit

actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter = CommonWriter(messageStringFormatter)
actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter =
CommonWriter(messageStringFormatter)
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

package co.touchlab.kermit

actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter = CommonWriter(messageStringFormatter)
actual fun platformLogWriter(messageStringFormatter: MessageStringFormatter): LogWriter =
CommonWriter(messageStringFormatter)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ internal class AtomicMutableLoggerConfig(logWriters: List<LogWriter>) : MutableL
}
}

actual fun mutableLoggerConfigInit(logWriters: List<LogWriter>): MutableLoggerConfig = AtomicMutableLoggerConfig(logWriters)
actual fun mutableLoggerConfigInit(logWriters: List<LogWriter>): MutableLoggerConfig =
AtomicMutableLoggerConfig(logWriters)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.test.Test

class LoggerExtensionsTest {
@Test
fun testCallingExtensions(){
fun testCallingExtensions() {
/*val testLogWriter = TestLogWriter(Severity.Verbose)
val log = Logger(loggerConfigInit(testLogWriter))
log.v("A")*/
Expand Down
4 changes: 2 additions & 2 deletions kermit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kotlin {
androidNativeArm64()
androidNativeX86()
androidNativeX64()

sourceSets {
val commonMain by getting {
dependencies {
Expand Down Expand Up @@ -106,7 +106,7 @@ kotlin {

mainSourceSet.dependsOn(nativeMain)
testSourceSet.dependsOn(nonKotlinTest)
}
}
}
}

Expand Down
24 changes: 12 additions & 12 deletions kermit/src/commonMain/kotlin/co/touchlab/kermit/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,62 +29,62 @@ open class Logger(
}

@JvmOverloads
inline fun v(throwable: Throwable? = null, tag: String = this.tag, message: () -> String){
inline fun v(throwable: Throwable? = null, tag: String = this.tag, message: () -> String) {
logBlock(Severity.Verbose, tag, throwable, message)
}

@JvmOverloads
inline fun d(throwable: Throwable? = null, tag: String = this.tag, message: () -> String){
inline fun d(throwable: Throwable? = null, tag: String = this.tag, message: () -> String) {
logBlock(Severity.Debug, tag, throwable, message)
}

@JvmOverloads
inline fun i(throwable: Throwable? = null, tag: String = this.tag, message: () -> String){
inline fun i(throwable: Throwable? = null, tag: String = this.tag, message: () -> String) {
logBlock(Severity.Info, tag, throwable, message)
}

@JvmOverloads
inline fun w(throwable: Throwable? = null, tag: String = this.tag, message: () -> String){
inline fun w(throwable: Throwable? = null, tag: String = this.tag, message: () -> String) {
logBlock(Severity.Warn, tag, throwable, message)
}

@JvmOverloads
inline fun e(throwable: Throwable? = null, tag: String = this.tag, message: () -> String){
inline fun e(throwable: Throwable? = null, tag: String = this.tag, message: () -> String) {
logBlock(Severity.Error, tag, throwable, message)
}

@JvmOverloads
inline fun a(throwable: Throwable? = null, tag: String = this.tag, message: () -> String){
inline fun a(throwable: Throwable? = null, tag: String = this.tag, message: () -> String) {
logBlock(Severity.Assert, tag, throwable, message)
}

@JvmOverloads
inline fun v(messageString: String, throwable: Throwable? = null, tag: String = this.tag){
inline fun v(messageString: String, throwable: Throwable? = null, tag: String = this.tag) {
log(Severity.Verbose, tag, throwable, messageString)
}

@JvmOverloads
inline fun d(messageString: String, throwable: Throwable? = null, tag: String = this.tag){
inline fun d(messageString: String, throwable: Throwable? = null, tag: String = this.tag) {
log(Severity.Debug, tag, throwable, messageString)
}

@JvmOverloads
inline fun i(messageString: String, throwable: Throwable? = null, tag: String = this.tag){
inline fun i(messageString: String, throwable: Throwable? = null, tag: String = this.tag) {
log(Severity.Info, tag, throwable, messageString)
}

@JvmOverloads
inline fun w(messageString: String, throwable: Throwable? = null, tag: String = this.tag){
inline fun w(messageString: String, throwable: Throwable? = null, tag: String = this.tag) {
log(Severity.Warn, tag, throwable, messageString)
}

@JvmOverloads
inline fun e(messageString: String, throwable: Throwable? = null, tag: String = this.tag){
inline fun e(messageString: String, throwable: Throwable? = null, tag: String = this.tag) {
log(Severity.Error, tag, throwable, messageString)
}

@JvmOverloads
inline fun a(messageString: String, throwable: Throwable? = null, tag: String = this.tag){
inline fun a(messageString: String, throwable: Throwable? = null, tag: String = this.tag) {
log(Severity.Assert, tag, throwable, messageString)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,6 @@ object MyLogger : Logger(
tag = "MyAppTag"
)

fun hello(){
fun hello() {
MyLogger.i { "Hello" }
}
Loading

0 comments on commit ae2b4e8

Please sign in to comment.