Skip to content

Commit

Permalink
Hide the public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeme Praks committed Feb 3, 2025
1 parent f3f6e3c commit 9ea5b2c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ class KotlinLoggingIrGenerationExtension(
val setMessageFunction = eventBuilderClassSymbol.owner.getPropertySetter("message")!!
@OptIn(UnsafeDuringIrConstructionAPI::class)
val setCauseFunction = eventBuilderClassSymbol.owner.getPropertySetter("cause")!!
@OptIn(UnsafeDuringIrConstructionAPI::class)
val setInternalCompilerDataFunction =
eventBuilderClassSymbol.owner.getPropertySetter("internalCompilerData")!!
val internalCompilerDataClassSymbol =
context.referenceClass(
ClassId(
Expand All @@ -109,6 +106,21 @@ class KotlinLoggingIrGenerationExtension(
)
)!!
@OptIn(UnsafeDuringIrConstructionAPI::class)
val setHiddenInternalCompilerDataFunction =
context
.referenceFunctions(
CallableId(
packageName = FqName(PACKAGE_NAME_INTERNAL),
Name.identifier("hiddenInternalCompilerData"),
)
)
.single {
it.owner.extensionReceiverParameter?.type?.classifierOrFail ==
eventBuilderClassSymbol.defaultType.classifierOrFail &&
it.owner.valueParameters.first().type.classifierOrFail ==
internalCompilerDataClassSymbol.defaultType.classifierOrFail
}
@OptIn(UnsafeDuringIrConstructionAPI::class)
val internalCompilerDataConstructor = internalCompilerDataClassSymbol.owner.primaryConstructor!!

val function0Class = context.irBuiltIns.functionN(0)
Expand Down Expand Up @@ -352,8 +364,8 @@ class KotlinLoggingIrGenerationExtension(
val eventBuilderLambdaBody = eventBuilderLambdaArgument.function.body!! as IrBlockBody
eventBuilderLambdaBody.statements.add(
0,
builder.irCall(typesHelper.setInternalCompilerDataFunction.owner).apply {
dispatchReceiver =
builder.irCall(typesHelper.setHiddenInternalCompilerDataFunction.owner).apply {
extensionReceiver =
IrGetValueImpl(
startOffset = UNDEFINED_OFFSET,
endOffset = UNDEFINED_OFFSET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class KLoggingEventBuilder {
* Internal data that is used by compiler plugin to provide additional information about the log
* site. Not intended for use by user code, API stability is not guaranteed.
*/
public var internalCompilerData: InternalCompilerData? = null
internal var internalCompilerData: InternalCompilerData? = null

public class InternalCompilerData(
public val messageTemplate: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ package io.github.oshai.kotlinlogging.internal
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KLoggingEventBuilder

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun KLoggingEventBuilder.hiddenInternalCompilerData(
compilerData: KLoggingEventBuilder.InternalCompilerData
) {
internalCompilerData = compilerData
}

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun KLogger.entryWithCompilerData(
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
vararg arguments: Any?,
Expand All @@ -11,13 +27,23 @@ public fun KLogger.entryWithCompilerData(
internalCompilerData = compilerData
}

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun KLogger.exitWithCompilerData(
compilerData: KLoggingEventBuilder.InternalCompilerData? = null
): Unit = atTrace {
message = "exit"
internalCompilerData = compilerData
}

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun <T> KLogger.exitWithCompilerData(
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
result: T,
Expand All @@ -29,6 +55,11 @@ public fun <T> KLogger.exitWithCompilerData(
return result
}

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun <T> KLogger.throwingWithCompilerData(
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
throwable: T,
Expand All @@ -41,6 +72,11 @@ public fun <T> KLogger.throwingWithCompilerData(
return throwable
}

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun <T> KLogger.catchingWithCompilerData(
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
throwable: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ internal object DefaultErrorMessageProducer {
fun getErrorLog(e: Exception): String = "Log message invocation failed: $e"
}

@Deprecated(
message = "This is an internal API and should not be used by user code",
level = DeprecationLevel.HIDDEN,
)
@Suppress("kotlin:S1133")
public fun Any?.castToThrowable(): Throwable? {
return if (this is Throwable) {
this
Expand Down

0 comments on commit 9ea5b2c

Please sign in to comment.