-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Common SDK log * Remove deprecated function
- Loading branch information
1 parent
781890d
commit 0a818bc
Showing
29 changed files
with
223 additions
and
197 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
78 changes: 78 additions & 0 deletions
78
MapboxSearch/sdk-common/src/main/java/com/mapbox/common/CommonSdkLog.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,78 @@ | ||
package com.mapbox.common | ||
|
||
import androidx.annotation.VisibleForTesting | ||
|
||
/** | ||
* This class in a "com.mapbox.common" package | ||
* because we need to access package-private com.mapbox.common.Log class from the Common SDK. | ||
*/ | ||
internal object CommonSdkLog { | ||
|
||
private const val SDK_IDENTIFIER = "search-sdk-android" | ||
|
||
private var logger: LogImpl? = CommonSdkLogImpl() | ||
|
||
/** | ||
* Resets implementation that uses Common SDK class which can't be loaded in unit tests. | ||
*/ | ||
@VisibleForTesting | ||
fun resetLogImpl() { | ||
logger = null | ||
} | ||
|
||
@VisibleForTesting | ||
fun reinitializeLogImpl() { | ||
logger = CommonSdkLogImpl() | ||
} | ||
|
||
fun logd(tag: String?, message: String) { | ||
logger?.logd(tag, message) | ||
} | ||
|
||
fun logi(tag: String?, message: String) { | ||
logger?.logi(tag, message) | ||
} | ||
|
||
fun logw(tag: String?, message: String) { | ||
logger?.logw(tag, message) | ||
} | ||
|
||
fun loge(tag: String?, message: String) { | ||
logger?.loge(tag, message) | ||
} | ||
|
||
private fun formatCategory(tag: String?): String { | ||
return when (tag) { | ||
null -> SDK_IDENTIFIER | ||
else -> "$SDK_IDENTIFIER\\$tag" | ||
} | ||
} | ||
|
||
private interface LogImpl { | ||
fun logd(tag: String?, message: String) | ||
|
||
fun logi(tag: String?, message: String) | ||
|
||
fun logw(tag: String?, message: String) | ||
|
||
fun loge(tag: String?, message: String) | ||
} | ||
|
||
private class CommonSdkLogImpl : LogImpl { | ||
override fun logd(tag: String?, message: String) { | ||
Log.debug(message, formatCategory(tag)) | ||
} | ||
|
||
override fun logi(tag: String?, message: String) { | ||
Log.info(message, formatCategory(tag)) | ||
} | ||
|
||
override fun logw(tag: String?, message: String) { | ||
Log.warning(message, formatCategory(tag)) | ||
} | ||
|
||
override fun loge(tag: String?, message: String) { | ||
Log.error(message, formatCategory(tag)) | ||
} | ||
} | ||
} |
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
43 changes: 16 additions & 27 deletions
43
MapboxSearch/sdk-common/src/main/java/com/mapbox/search/common/logger/Log.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 |
---|---|---|
@@ -1,41 +1,30 @@ | ||
package com.mapbox.search.common.logger | ||
|
||
import com.mapbox.base.common.logger.Logger | ||
import com.mapbox.base.common.logger.model.Message | ||
import com.mapbox.base.common.logger.model.Tag | ||
import androidx.annotation.VisibleForTesting | ||
import com.mapbox.common.CommonSdkLog | ||
|
||
const val DEFAULT_SEARCH_SDK_LOG_TAG = "SearchSDK" | ||
|
||
var searchSdkLogger: Logger? = null | ||
|
||
fun logd(throwable: Throwable, message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.d(tag = Tag(tag), msg = Message(message), tr = throwable) | ||
} | ||
|
||
fun logd(message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.d(tag = Tag(tag), msg = Message(message)) | ||
} | ||
|
||
fun logi(throwable: Throwable, message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.i(tag = Tag(tag), msg = Message(message), tr = throwable) | ||
@VisibleForTesting | ||
fun resetLogImpl() { | ||
CommonSdkLog.resetLogImpl() | ||
} | ||
|
||
fun logi(message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.i(tag = Tag(tag), msg = Message(message)) | ||
@VisibleForTesting | ||
fun reinitializeLogImpl() { | ||
CommonSdkLog.resetLogImpl() | ||
} | ||
|
||
fun logw(throwable: Throwable, message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.w(tag = Tag(tag), msg = Message(message), tr = throwable) | ||
fun logd(message: String, tag: String? = null) { | ||
CommonSdkLog.logd(tag, message) | ||
} | ||
|
||
fun logw(message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.w(tag = Tag(tag), msg = Message(message)) | ||
fun logi(message: String, tag: String? = null) { | ||
CommonSdkLog.logi(tag, message) | ||
} | ||
|
||
fun loge(throwable: Throwable, message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.e(tag = Tag(tag), msg = Message(message), tr = throwable) | ||
fun logw(message: String, tag: String? = null) { | ||
CommonSdkLog.logw(tag, message) | ||
} | ||
|
||
fun loge(message: String, tag: String = DEFAULT_SEARCH_SDK_LOG_TAG) { | ||
searchSdkLogger?.e(tag = Tag(tag), msg = Message(message)) | ||
fun loge(message: String, tag: String? = null) { | ||
CommonSdkLog.loge(tag, message) | ||
} |
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
Oops, something went wrong.