From 264ce4e181914556c39115b0dafd050ea78b9b84 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Wed, 5 Oct 2022 12:21:39 +0200 Subject: [PATCH 1/7] introduced lazy logging --- .../mapbox/navigation/base/route/NavigationRoute.kt | 7 +++---- .../mapbox/navigation/utils/internal/LoggerFrontend.kt | 10 ++++++++++ .../mapbox/navigation/utils/internal/LoggerProvider.kt | 10 ++++++++++ .../navigation/testing/LoggingFrontendTestRule.kt | 3 +++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libnavigation-base/src/main/java/com/mapbox/navigation/base/route/NavigationRoute.kt b/libnavigation-base/src/main/java/com/mapbox/navigation/base/route/NavigationRoute.kt index b0f2af9296b..69d0afd1ffe 100644 --- a/libnavigation-base/src/main/java/com/mapbox/navigation/base/route/NavigationRoute.kt +++ b/libnavigation-base/src/main/java/com/mapbox/navigation/base/route/NavigationRoute.kt @@ -184,10 +184,9 @@ class NavigationRoute internal constructor( } val deferredRouteOptionsParsing = async(ThreadController.DefaultDispatcher) { RouteOptions.fromUrl(URL(routeRequestUrl)).also { - logD( - "parsed request url to RouteOptions: ${it.toUrl("***")}", - LOG_CATEGORY - ) + logD(LOG_CATEGORY) { + "parsed request url to RouteOptions: ${it.toUrl("***")}" + } } } create( diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt index 0b14d077621..1a963485f7c 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt @@ -1,5 +1,7 @@ package com.mapbox.navigation.utils.internal +import com.mapbox.common.LogConfiguration +import com.mapbox.common.LoggingLevel import com.mapbox.common.NativeLoggerWrapper private const val NAV_SDK_CATEGORY = "nav-sdk" @@ -7,6 +9,7 @@ private const val NAV_SDK_CATEGORY = "nav-sdk" interface LoggerFrontend { fun logV(msg: String, category: String? = null) fun logD(msg: String, category: String? = null) + fun logD(category: String? = null, lazyMsg: () -> String) fun logI(msg: String, category: String? = null) fun logE(msg: String, category: String? = null) fun logW(msg: String, category: String? = null) @@ -24,6 +27,13 @@ internal class MapboxCommonLoggerFrontend : LoggerFrontend { NativeLoggerWrapper.debug(message, NAV_SDK_CATEGORY) } + override fun logD(category: String?, lazyMsg: () -> String) { + when (LogConfiguration.getLoggingLevel()) { + LoggingLevel.DEBUG -> logD(lazyMsg(), category) + LoggingLevel.ERROR, LoggingLevel.INFO, LoggingLevel.WARNING -> { } + } + } + override fun logI(msg: String, category: String?) { val message = createMessage(msg, category) NativeLoggerWrapper.info(message, NAV_SDK_CATEGORY) diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt index 1b5e63d03ef..c8e8710495b 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt @@ -39,6 +39,16 @@ fun logD(msg: String, category: String? = null) { LoggerProvider.frontend.logD(msg, category) } +/** + * @param category optional string to identify the source or category of the log message. + * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose then Debug. + * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. + * As an example, this is how the logs would look like `D/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. + */ +fun logD(category: String? = null, lazyMsg: () -> String) { + LoggerProvider.frontend.logD(category, lazyMsg) +} + /** * @param msg to log. * @param category optional string to identify the source or category of the log message. diff --git a/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt b/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt index 87eeedc4ac2..cbfff4c82e9 100644 --- a/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt +++ b/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt @@ -14,6 +14,9 @@ private object NoLoggingFrontend : LoggerFrontend { override fun logD(msg: String, category: String?) { } + override fun logD(category: String?, lazyMsg: () -> String) { + } + override fun logI(msg: String, category: String?) { } From 9858d51b5a032e008c43aa7ced4e9cfa0a59f3c7 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Wed, 5 Oct 2022 19:07:45 +0200 Subject: [PATCH 2/7] made log inline --- .../com/mapbox/common/NativeLoggerWrapper.kt | 2 + .../utils/internal/LoggerFrontend.kt | 13 +- .../utils/internal/LoggerProvider.kt | 12 +- .../utils/internal/LoggingLevelUtil.kt | 15 ++ .../utils/internal/LoggingLevelUtilKtTest.kt | 135 ++++++++++++++++++ .../testing/LoggingFrontendTestRule.kt | 7 +- 6 files changed, 170 insertions(+), 14 deletions(-) create mode 100644 libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt create mode 100644 libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt diff --git a/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt b/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt index 492b22d5d8d..aab6fe5acb5 100644 --- a/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt +++ b/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt @@ -20,4 +20,6 @@ internal object NativeLoggerWrapper { fun error(message: String, category: String?) { Log.error(message, category) } + + fun getLogLevel() = LogConfiguration.getLoggingLevel() } diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt index 1a963485f7c..eba05c3c202 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt @@ -1,21 +1,23 @@ package com.mapbox.navigation.utils.internal -import com.mapbox.common.LogConfiguration import com.mapbox.common.LoggingLevel import com.mapbox.common.NativeLoggerWrapper private const val NAV_SDK_CATEGORY = "nav-sdk" interface LoggerFrontend { + fun getLogLevel(): LoggingLevel? fun logV(msg: String, category: String? = null) fun logD(msg: String, category: String? = null) - fun logD(category: String? = null, lazyMsg: () -> String) fun logI(msg: String, category: String? = null) fun logE(msg: String, category: String? = null) fun logW(msg: String, category: String? = null) } internal class MapboxCommonLoggerFrontend : LoggerFrontend { + + override fun getLogLevel() = NativeLoggerWrapper.getLogLevel() + override fun logV(msg: String, category: String?) { val message = createMessage(msg, category) // There's no com.mapbox.common.Log.verbose available - using Log.debug instead @@ -27,13 +29,6 @@ internal class MapboxCommonLoggerFrontend : LoggerFrontend { NativeLoggerWrapper.debug(message, NAV_SDK_CATEGORY) } - override fun logD(category: String?, lazyMsg: () -> String) { - when (LogConfiguration.getLoggingLevel()) { - LoggingLevel.DEBUG -> logD(lazyMsg(), category) - LoggingLevel.ERROR, LoggingLevel.INFO, LoggingLevel.WARNING -> { } - } - } - override fun logI(msg: String, category: String?) { val message = createMessage(msg, category) NativeLoggerWrapper.info(message, NAV_SDK_CATEGORY) diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt index c8e8710495b..456f9596c2c 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt @@ -2,6 +2,7 @@ package com.mapbox.navigation.utils.internal import androidx.annotation.VisibleForTesting import com.mapbox.base.common.logger.Logger +import com.mapbox.common.LoggingLevel /** * Singleton provider of [Logger]. @@ -45,8 +46,10 @@ fun logD(msg: String, category: String? = null) { * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `D/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ -fun logD(category: String? = null, lazyMsg: () -> String) { - LoggerProvider.frontend.logD(category, lazyMsg) +inline fun logD(category: String? = null, lazyMsg: () -> String) { + if (logLevel().atLeast(LoggingLevel.DEBUG)) { + logD(lazyMsg(), category) + } } /** @@ -78,3 +81,8 @@ fun logW(msg: String, category: String? = null) { fun logE(msg: String, category: String? = null) { LoggerProvider.frontend.logE(msg, category) } + +/** + * Should not be used directly. Added to support inline calls. + */ +fun logLevel() = LoggerProvider.frontend.getLogLevel() diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt new file mode 100644 index 00000000000..6faf7676bbc --- /dev/null +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt @@ -0,0 +1,15 @@ +package com.mapbox.navigation.utils.internal + +import com.mapbox.common.LoggingLevel + +fun LoggingLevel?.atLeast(loggingLevel: LoggingLevel): Boolean { + return toPriority(this) >= toPriority(loggingLevel) +} + +private fun toPriority(loggingLevel: LoggingLevel?) = when (loggingLevel) { + null -> 0 + LoggingLevel.DEBUG -> 1 + LoggingLevel.INFO -> 2 + LoggingLevel.WARNING -> 3 + LoggingLevel.ERROR -> 4 +} \ No newline at end of file diff --git a/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt b/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt new file mode 100644 index 00000000000..05d5e0e2be6 --- /dev/null +++ b/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt @@ -0,0 +1,135 @@ +package com.mapbox.navigation.utils.internal + +import com.mapbox.common.LoggingLevel +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +@RunWith(Parameterized::class) +class LoggingLevelUtilKtTest(val parameter: LogLevelData) { + + companion object { + + @JvmStatic + @Parameterized.Parameters(name = "{0}") + fun parameters() = listOf( + LogLevelData( + what = null, + atLeast = LoggingLevel.ERROR, + expected = false + ), + LogLevelData( + what = null, + atLeast = LoggingLevel.WARNING, + expected = false + ), + LogLevelData( + what = null, + atLeast = LoggingLevel.INFO, + expected = false + ), + LogLevelData( + what = null, + atLeast = LoggingLevel.DEBUG, + expected = false + ), + + LogLevelData( + what = LoggingLevel.ERROR, + atLeast = LoggingLevel.ERROR, + expected = true + ), + LogLevelData( + what = LoggingLevel.ERROR, + atLeast = LoggingLevel.WARNING, + expected = true + ), + LogLevelData( + what = LoggingLevel.ERROR, + atLeast = LoggingLevel.INFO, + expected = true + ), + LogLevelData( + what = LoggingLevel.ERROR, + atLeast = LoggingLevel.DEBUG, + expected = true + ), + + LogLevelData( + what = LoggingLevel.WARNING, + atLeast = LoggingLevel.ERROR, + expected = false + ), + LogLevelData( + what = LoggingLevel.WARNING, + atLeast = LoggingLevel.WARNING, + expected = true + ), + LogLevelData( + what = LoggingLevel.ERROR, + atLeast = LoggingLevel.INFO, + expected = true + ), + LogLevelData( + what = LoggingLevel.ERROR, + atLeast = LoggingLevel.DEBUG, + expected = true + ), + + LogLevelData( + what = LoggingLevel.INFO, + atLeast = LoggingLevel.ERROR, + expected = false + ), + LogLevelData( + what = LoggingLevel.INFO, + atLeast = LoggingLevel.WARNING, + expected = false + ), + LogLevelData( + what = LoggingLevel.INFO, + atLeast = LoggingLevel.INFO, + expected = true + ), + LogLevelData( + what = LoggingLevel.INFO, + atLeast = LoggingLevel.DEBUG, + expected = true + ), + + LogLevelData( + what = LoggingLevel.DEBUG, + atLeast = LoggingLevel.ERROR, + expected = false + ), + LogLevelData( + what = LoggingLevel.DEBUG, + atLeast = LoggingLevel.WARNING, + expected = false + ), + LogLevelData( + what = LoggingLevel.DEBUG, + atLeast = LoggingLevel.INFO, + expected = false + ), + LogLevelData( + what = LoggingLevel.DEBUG, + atLeast = LoggingLevel.DEBUG, + expected = true + ), + ) + } + + @Test + fun `test atLeast`() { + val result = parameter.what.atLeast(parameter.atLeast) + assertEquals(parameter.expected, result) + } + + data class LogLevelData( + val what: LoggingLevel?, + val atLeast: LoggingLevel, + val expected: Boolean + ) +} \ No newline at end of file diff --git a/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt b/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt index cbfff4c82e9..83abc88ba1f 100644 --- a/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt +++ b/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt @@ -1,6 +1,7 @@ package com.mapbox.navigation.testing import android.annotation.SuppressLint +import com.mapbox.common.LoggingLevel import com.mapbox.navigation.utils.internal.LoggerFrontend import com.mapbox.navigation.utils.internal.LoggerProvider import org.junit.rules.TestRule @@ -8,15 +9,15 @@ import org.junit.runner.Description import org.junit.runners.model.Statement private object NoLoggingFrontend : LoggerFrontend { + + override fun getLogLevel(): LoggingLevel? = null + override fun logV(msg: String, category: String?) { } override fun logD(msg: String, category: String?) { } - override fun logD(category: String?, lazyMsg: () -> String) { - } - override fun logI(msg: String, category: String?) { } From 773484f85a1379c51bc6efe693057a5e6c3aec71 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Wed, 5 Oct 2022 19:11:47 +0200 Subject: [PATCH 3/7] fixed styles + added lazy messages to all log options --- .../utils/internal/LoggerProvider.kt | 38 ++++++++++++++++++- .../utils/internal/LoggingLevelUtil.kt | 2 +- .../utils/internal/LoggingLevelUtilKtTest.kt | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt index 456f9596c2c..38528f05069 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt @@ -42,7 +42,7 @@ fun logD(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose then Debug. + * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Debug. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `D/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -62,6 +62,18 @@ fun logI(msg: String, category: String? = null) { LoggerProvider.frontend.logI(msg, category) } +/** + * @param category optional string to identify the source or category of the log message. + * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Inline. + * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. + * As an example, this is how the logs would look like `I/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. + */ +inline fun logI(category: String? = null, lazyMsg: () -> String) { + if (logLevel().atLeast(LoggingLevel.INFO)) { + logI(lazyMsg(), category) + } +} + /** * @param msg to log. * @param category optional string to identify the source or category of the log message. @@ -72,6 +84,18 @@ fun logW(msg: String, category: String? = null) { LoggerProvider.frontend.logW(msg, category) } +/** + * @param category optional string to identify the source or category of the log message. + * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Warning. + * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. + * As an example, this is how the logs would look like `W/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. + */ +inline fun logW(category: String? = null, lazyMsg: () -> String) { + if (logLevel().atLeast(LoggingLevel.WARNING)) { + logW(lazyMsg(), category) + } +} + /** * @param msg to log. * @param category optional string to identify the source or category of the log message. @@ -82,6 +106,18 @@ fun logE(msg: String, category: String? = null) { LoggerProvider.frontend.logE(msg, category) } +/** + * @param category optional string to identify the source or category of the log message. + * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Error. + * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. + * As an example, this is how the logs would look like `E/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. + */ +inline fun logE(category: String? = null, lazyMsg: () -> String) { + if (logLevel().atLeast(LoggingLevel.ERROR)) { + logE(lazyMsg(), category) + } +} + /** * Should not be used directly. Added to support inline calls. */ diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt index 6faf7676bbc..baf5cbf3c3e 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggingLevelUtil.kt @@ -12,4 +12,4 @@ private fun toPriority(loggingLevel: LoggingLevel?) = when (loggingLevel) { LoggingLevel.INFO -> 2 LoggingLevel.WARNING -> 3 LoggingLevel.ERROR -> 4 -} \ No newline at end of file +} diff --git a/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt b/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt index 05d5e0e2be6..148e8232a90 100644 --- a/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt +++ b/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt @@ -132,4 +132,4 @@ class LoggingLevelUtilKtTest(val parameter: LogLevelData) { val atLeast: LoggingLevel, val expected: Boolean ) -} \ No newline at end of file +} From 60c5793eaed95230d732bbc9ae24e63faf395b72 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Thu, 6 Oct 2022 09:06:01 +0200 Subject: [PATCH 4/7] fixed tests --- .../navigation/utils/internal/LoggingLevelUtilKtTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt b/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt index 148e8232a90..ab81b4c9d95 100644 --- a/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt +++ b/libnavigation-util/src/test/java/com/mapbox/navigation/utils/internal/LoggingLevelUtilKtTest.kt @@ -67,12 +67,12 @@ class LoggingLevelUtilKtTest(val parameter: LogLevelData) { expected = true ), LogLevelData( - what = LoggingLevel.ERROR, + what = LoggingLevel.WARNING, atLeast = LoggingLevel.INFO, expected = true ), LogLevelData( - what = LoggingLevel.ERROR, + what = LoggingLevel.WARNING, atLeast = LoggingLevel.DEBUG, expected = true ), From 5a5c55c37281c9fd849256c0e6c4c3590583e861 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Thu, 6 Oct 2022 09:17:48 +0200 Subject: [PATCH 5/7] clarified docs --- .../navigation/utils/internal/LoggerProvider.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt index 38528f05069..81f21b01afc 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt @@ -42,7 +42,7 @@ fun logD(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Debug. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Debug. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `D/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -64,7 +64,7 @@ fun logI(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Inline. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Info. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `I/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -86,7 +86,7 @@ fun logW(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Warning. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Warning. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `W/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -108,7 +108,7 @@ fun logE(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. Isn't executed if current log level less verbose than Error. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Error. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `E/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -119,6 +119,7 @@ inline fun logE(category: String? = null, lazyMsg: () -> String) { } /** - * Should not be used directly. Added to support inline calls. + * Should not be used directly. + * Added to support inline calls. Public inline functions can use only public API inside. */ fun logLevel() = LoggerProvider.frontend.getLogLevel() From d138292ac20d8fbdca53552d8bdaba0d4e271b33 Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Thu, 6 Oct 2022 09:20:38 +0200 Subject: [PATCH 6/7] fixed docs --- .../mapbox/navigation/utils/internal/LoggerProvider.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt index 81f21b01afc..56532c648d9 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerProvider.kt @@ -42,7 +42,7 @@ fun logD(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Debug. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level is less verbose than Debug. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `D/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -64,7 +64,7 @@ fun logI(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Info. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level is less verbose than Info. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `I/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -86,7 +86,7 @@ fun logW(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Warning. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level is less verbose than Warning. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `W/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ @@ -108,7 +108,7 @@ fun logE(msg: String, category: String? = null) { /** * @param category optional string to identify the source or category of the log message. - * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level less verbose than Error. + * @param lazyMsg is a lazy message to log. The lazy message isn't executed if current log level is less verbose than Error. * Noting that the category is appended to the log message to give extra context along with the `[nav-sdk]` parent category. * As an example, this is how the logs would look like `E/Mapbox: [nav-sdk] [ConnectivityHandler] NetworkStatus=ReachableViaWiFi`. */ From 0a76da4fb12ff21c3396403918b72a1d273af92f Mon Sep 17 00:00:00 2001 From: VysotskiVadim Date: Thu, 6 Oct 2022 09:49:21 +0200 Subject: [PATCH 7/7] fixed getting of log level from common --- .../src/main/java/com/mapbox/common/NativeLoggerWrapper.kt | 2 +- .../java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt | 2 +- .../com/mapbox/navigation/testing/LoggingFrontendTestRule.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt b/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt index aab6fe5acb5..125bbc0981c 100644 --- a/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt +++ b/libnavigation-util/src/main/java/com/mapbox/common/NativeLoggerWrapper.kt @@ -21,5 +21,5 @@ internal object NativeLoggerWrapper { Log.error(message, category) } - fun getLogLevel() = LogConfiguration.getLoggingLevel() + fun getLogLevel(category: String) = LogConfiguration.getLoggingLevel(category) } diff --git a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt index eba05c3c202..133867ef4df 100644 --- a/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt +++ b/libnavigation-util/src/main/java/com/mapbox/navigation/utils/internal/LoggerFrontend.kt @@ -16,7 +16,7 @@ interface LoggerFrontend { internal class MapboxCommonLoggerFrontend : LoggerFrontend { - override fun getLogLevel() = NativeLoggerWrapper.getLogLevel() + override fun getLogLevel() = NativeLoggerWrapper.getLogLevel(NAV_SDK_CATEGORY) override fun logV(msg: String, category: String?) { val message = createMessage(msg, category) diff --git a/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt b/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt index 83abc88ba1f..f38860fc18a 100644 --- a/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt +++ b/libtesting-navigation-util/src/main/java/com/mapbox/navigation/testing/LoggingFrontendTestRule.kt @@ -10,7 +10,7 @@ import org.junit.runners.model.Statement private object NoLoggingFrontend : LoggerFrontend { - override fun getLogLevel(): LoggingLevel? = null + override fun getLogLevel(): LoggingLevel = LoggingLevel.DEBUG override fun logV(msg: String, category: String?) { }