Skip to content

Commit

Permalink
minor logging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
olme04 committed Mar 10, 2022
1 parent c1a8d97 commit 4a7bedb
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 46 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/TestOptIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ fun LanguageSettingsBuilder.optInForTest() {
optIn("io.rsocket.kotlin.TransportApi")
optIn("io.rsocket.kotlin.ExperimentalMetadataApi")
optIn("io.rsocket.kotlin.ExperimentalStreamsApi")
optIn("io.rsocket.kotlin.RSocketLoggingApi")
optIn("io.rsocket.kotlin.logging.ExperimentalLoggingApi")
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,4 @@ public annotation class ExperimentalMetadataApi
)
public annotation class ExperimentalStreamsApi

@Retention(value = AnnotationRetention.BINARY)
@RequiresOptIn(
level = RequiresOptIn.Level.WARNING,
message = "This is mostly internal API used for logging. This API can change in future in non backwards-compatible manner."
)
public annotation class RSocketLoggingApi


Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

@file:OptIn(TransportApi::class, RSocketLoggingApi::class)
@file:OptIn(TransportApi::class, ExperimentalLoggingApi::class)

package io.rsocket.kotlin.internal
package io.rsocket.kotlin.connect

import io.ktor.utils.io.core.*
import io.rsocket.kotlin.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

@file:OptIn(TransportApi::class, RSocketLoggingApi::class)
@file:OptIn(TransportApi::class, ExperimentalLoggingApi::class)

package io.rsocket.kotlin.connect

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package io.rsocket.kotlin.connect

import io.rsocket.kotlin.*
import io.rsocket.kotlin.logging.*

public sealed interface RSocketPeerProvider {
@RSocketLoggingApi
@ExperimentalLoggingApi
public val loggerFactory: LoggerFactory
}

//TODO: naming
public sealed interface RSocketPeerProviderBuilder {
@RSocketLoggingApi
@ExperimentalLoggingApi
public fun loggerFactory(factory: LoggerFactory)

public fun beforePeerConfiguration(configurator: RSocketConnectConfigurator)
Expand All @@ -23,15 +22,15 @@ public sealed interface RSocketPeerProviderBuilder {
}

internal abstract class RSocketPeerBuilderImpl : RSocketPeerProviderBuilder {
@RSocketLoggingApi
@ExperimentalLoggingApi
protected var loggerFactory: LoggerFactory = DefaultLoggerFactory
private set

protected val beforeConfigurators = mutableListOf<RSocketConnectConfigurator>()
protected val afterConfigurators = mutableListOf<RSocketConnectConfigurator>()
protected var defaultConfigurator: RSocketConnectConfigurator? = null

@RSocketLoggingApi
@ExperimentalLoggingApi
final override fun loggerFactory(factory: LoggerFactory) {
loggerFactory = factory
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

@file:OptIn(TransportApi::class, RSocketLoggingApi::class)
@file:OptIn(TransportApi::class, ExperimentalLoggingApi::class)

package io.rsocket.kotlin.connect

import io.rsocket.kotlin.*
import io.rsocket.kotlin.core.*
import io.rsocket.kotlin.frame.*
import io.rsocket.kotlin.frame.io.*
import io.rsocket.kotlin.internal.*
import io.rsocket.kotlin.logging.*
import io.rsocket.kotlin.transport.*
import kotlinx.coroutines.*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.rsocket.kotlin.logging

@Retention(value = AnnotationRetention.BINARY)
@RequiresOptIn(
level = RequiresOptIn.Level.WARNING,
message = "This is mostly internal API used for logging. This API can change in future in non backwards-compatible manner."
)
public annotation class ExperimentalLoggingApi
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,25 @@

package io.rsocket.kotlin.logging

import io.rsocket.kotlin.*

@RSocketLoggingApi
@ExperimentalLoggingApi
public enum class LoggingLevel { TRACE, DEBUG, INFO, WARN, ERROR }

@RSocketLoggingApi
@ExperimentalLoggingApi
public fun interface LoggerFactory {
public fun logger(tag: String): Logger
}

@RSocketLoggingApi
@ExperimentalLoggingApi
internal expect val DefaultLoggerFactory: LoggerFactory

@RSocketLoggingApi
@ExperimentalLoggingApi
public interface Logger {
public val tag: String
public fun isLoggable(level: LoggingLevel): Boolean
public fun rawLog(level: LoggingLevel, throwable: Throwable?, message: Any?)
}

@RSocketLoggingApi
@ExperimentalLoggingApi
public inline fun Logger.log(level: LoggingLevel, throwable: Throwable? = null, message: () -> Any?) {
if (!isLoggable(level)) return

Expand All @@ -48,27 +46,27 @@ public inline fun Logger.log(level: LoggingLevel, throwable: Throwable? = null,
rawLog(level, throwable, msg)
}

@RSocketLoggingApi
@ExperimentalLoggingApi
public inline fun Logger.trace(throwable: Throwable? = null, message: () -> Any?) {
log(LoggingLevel.TRACE, throwable, message)
}

@RSocketLoggingApi
@ExperimentalLoggingApi
public inline fun Logger.debug(throwable: Throwable? = null, message: () -> Any?) {
log(LoggingLevel.DEBUG, throwable, message)
}

@RSocketLoggingApi
@ExperimentalLoggingApi
public inline fun Logger.info(throwable: Throwable? = null, message: () -> Any?) {
log(LoggingLevel.INFO, throwable, message)
}

@RSocketLoggingApi
@ExperimentalLoggingApi
public inline fun Logger.warn(throwable: Throwable? = null, message: () -> Any?) {
log(LoggingLevel.WARN, throwable, message)
}

@RSocketLoggingApi
@ExperimentalLoggingApi
public inline fun Logger.error(throwable: Throwable? = null, message: () -> Any?) {
log(LoggingLevel.ERROR, throwable, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package io.rsocket.kotlin.logging

import io.rsocket.kotlin.*

/**
* Logger implementation, that never print
*/
@RSocketLoggingApi
@ExperimentalLoggingApi
public object NoopLogger : Logger, LoggerFactory {
override val tag: String get() = "noop"
override fun isLoggable(level: LoggingLevel): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package io.rsocket.kotlin.logging

import io.rsocket.kotlin.*

@RSocketLoggingApi
@ExperimentalLoggingApi
public class PrintLogger(
override val tag: String,
private val minLevel: LoggingLevel = LoggingLevel.INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

package io.rsocket.kotlin.logging

import io.rsocket.kotlin.*

@RSocketLoggingApi
@ExperimentalLoggingApi
internal actual val DefaultLoggerFactory: LoggerFactory
get() = ConsoleLogger

@RSocketLoggingApi
@ExperimentalLoggingApi
public class ConsoleLogger(
override val tag: String,
private val minLevel: LoggingLevel = LoggingLevel.INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package io.rsocket.kotlin.logging

import io.rsocket.kotlin.*
import java.util.logging.*
import java.util.logging.Level as JLevel
import java.util.logging.Logger as JLogger

@RSocketLoggingApi
@ExperimentalLoggingApi
internal actual val DefaultLoggerFactory: LoggerFactory
get() = JavaLogger

@RSocketLoggingApi
@ExperimentalLoggingApi
public class JavaLogger(override val tag: String) : Logger {
private val jLogger = JLogger.getLogger(tag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.rsocket.kotlin.logging

import io.rsocket.kotlin.*

@RSocketLoggingApi
@ExperimentalLoggingApi
public actual val DefaultLoggerFactory: LoggerFactory
get() = PrintLogger

0 comments on commit 4a7bedb

Please sign in to comment.