AAkira / Napier

Logging library for Kotlin Multiplatform
Apache License 2.0
785 stars 34 forks source link

feat(Napier): Add top-level function and some changes #94

Closed ghasemdev closed 2 years ago

ghasemdev commented 2 years ago

Changes:

Please accept pull request.

AAkira commented 2 years ago

@ghasemdev I really appreciate your help. This is nice!

Please fix the test and swift code.

Change the message_.

shared.log(
            priority: logLevel,
            tag: tag ?? {
                let fileName = URL(fileURLWithPath: file).lastPathComponent
                let functionName: String
                if let firstBraceIndex = function.firstIndex(of: "(") {
                    functionName = String(function[..<firstBraceIndex])
                } else {
                    functionName = function
                }
                return "\(fileName):\(functionName)"
            }(),
            throwable: nil,
            message: message
        )
ghasemdev commented 2 years ago

@ghasemdev I really appreciate your help. This is nice!

Please fix the test and swift code.

  • ios/Napier/Napier.swift

Change the message_.

shared.log(
            priority: logLevel,
            tag: tag ?? {
                let fileName = URL(fileURLWithPath: file).lastPathComponent
                let functionName: String
                if let firstBraceIndex = function.firstIndex(of: "(") {
                    functionName = String(function[..<firstBraceIndex])
                } else {
                    functionName = function
                }
                return "\(fileName):\(functionName)"
            }(),
            throwable: nil,
            message: message
        )

Thanks, Also I fixed that problem.

AAkira commented 2 years ago

Sorry for pointing this out again and again. Does it need to reorder the arguments of the previously defined function?

The sample project doesn't work now.

    fun handleError() {
        try {
            throw Exception("throw error")
        } catch (e: Exception) {
            Napier.e("Napier Error", e) // error
        }
    }

The order of the arguments should remain the same as before because I think there are only a few situations where a tag is used.

ghasemdev commented 2 years ago

Sorry for pointing this out again and again. Does it need to reorder the arguments of the previously defined function?

The sample project doesn't work now.

  • mpp-sample/src/commonMain/.../Sample.kt
    fun handleError() {
        try {
            throw Exception("throw error")
        } catch (e: Exception) {
            Napier.e("Napier Error", e) // error
        }
    }

The order of the arguments should remain the same as before because I think there are only a few situations where a tag is used.

I think you are right. I did not notice that we can configure the tag through the DebugAntilog class. I'm sorry that most of the tests lead to errors. I don't have Android SDK in the IntelliJ and the project dependencies are not installed properly and I can't run the tests.

I fix issue and commit again.

ghasemdev commented 2 years ago

I have another question, This enum class is un useless?

image

AAkira commented 2 years ago

Thank you so mush! LGTM

I have another question, This enum class is un useless?

I forgot to delete it in this PR. I'll fix it in another PR. Thank you.