Skip to content

Commit

Permalink
refactor: revert static API and change to deprecated to avoid crash
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentdelmundo authored Jun 14, 2022
1 parent fdffa09 commit e21f80a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ val retrofit = Retrofit.Builder().build("your_baseUrl", okHttpClient gsonConvert

### v2.0.0 (in-progress)
* SDKCF-5390: **Breaking Changes:** Moved `setDebugLevel()` and `setDebug()` APIs from static to `Logger` class APIs. This will allow multiple SDK app dependencies to have their own debug logging configuration.
- Deprecated `Logger.setDebugLevel()` and `Logger.setDebug()` static APIs. These APIs will no longer work but not removed to avoid crashes on incompatible SDK versions.

### v1.2.0 (2022-05-19)
* SDKCF-5292: Set initOrder of the content provider to a high value to make sure that it is initialized before the host app ContentProvider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,26 @@ open class Logger(private val tag: String = "") {
companion object {
private const val MAX_LOG_LENGTH = 4000
private const val INITIAL_SIZE = 256

/**
* This method enables/disables debug logger.
* By default only info, warn and error are logged. Debug is only logged
* if [Logger.setDebug] is called with `true`.
* @param debug true to enable debug, false otherwise
*/
@Deprecated("Using this method will have no effect.",
ReplaceWith("`loggerInstance.setDebug(<true/false>)`"))
fun setDebug(debug: Boolean) = Unit

/**
* Set the level of the stack trace line to be logged.
* The element at the top of the stack (stackFramePosition = 0) represents the execution
* point at which the stack trace was generated.
*
* @param stackFramePosition the position of the stack trace element to be logged.
*/
@Deprecated("Using this method will have no effect.",
ReplaceWith("`loggerInstance.setDebugLevel(<value>)`"))
fun setDebugLevel(stackFramePosition: Int) = Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class LoggerSpec {
assertThatLog().hasNoMoreMessages()
}

@Test
fun `should not enable debug in set debug static api`() {
Logger.setDebug(true)
logger.debug("some debug log")
assertThatLog().hasNoMoreMessages()
}

@Test
fun `should enable debug and verbose logging in set debug`() {
logger.setDebug(true)
Expand Down Expand Up @@ -117,6 +124,10 @@ class LoggerSpec {
logger.setDebugLevel(-1)
logger.debug(Throwable(), "test")
assertThatLog().hasMessage(Log.DEBUG, TAG, "test")

Logger.setDebugLevel(100)
logger.debug(Throwable(), "test")
assertThatLog().hasMessage(Log.DEBUG, TAG, "test")
}

private fun assertThatLog() = LogAssert(ShadowLog.getLogs())
Expand Down

0 comments on commit e21f80a

Please sign in to comment.