Skip to content

Commit 2b2dbc7

Browse files
neeme-praks-sympowerNeeme Praks
and
Neeme Praks
authored
Changes needed for compiler plugin (#474)
* Changes needed for compiler plugin * Hide the public API * Hide also toStringSafe() and castToThrowable() extension functions --------- Co-authored-by: Neeme Praks <neeme.praks@eesti.ee>
1 parent e14380d commit 2b2dbc7

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEventBuilder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class KLoggingEventBuilder {
1111
* Internal data that is used by compiler plugin to provide additional information about the log
1212
* site. Not intended for use by user code, API stability is not guaranteed.
1313
*/
14-
public var internalCompilerData: InternalCompilerData? = null
14+
internal var internalCompilerData: InternalCompilerData? = null
1515

1616
public class InternalCompilerData(
1717
public val messageTemplate: String? = null,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package io.github.oshai.kotlinlogging.internal
2+
3+
import io.github.oshai.kotlinlogging.KLogger
4+
import io.github.oshai.kotlinlogging.KLoggingEventBuilder
5+
6+
@Deprecated(
7+
message = "This is an internal API and should not be used by user code",
8+
level = DeprecationLevel.HIDDEN,
9+
)
10+
@Suppress("kotlin:S1133")
11+
public fun (() -> Any?).hiddenToStringSafe(): String = toStringSafe()
12+
13+
@Deprecated(
14+
message = "This is an internal API and should not be used by user code",
15+
level = DeprecationLevel.HIDDEN,
16+
)
17+
@Suppress("kotlin:S1133")
18+
public fun Any?.hiddenCastToThrowable(): Throwable? {
19+
return if (this is Throwable) {
20+
this
21+
} else {
22+
null
23+
}
24+
}
25+
26+
@Deprecated(
27+
message = "This is an internal API and should not be used by user code",
28+
level = DeprecationLevel.HIDDEN,
29+
)
30+
@Suppress("kotlin:S1133")
31+
public fun KLoggingEventBuilder.hiddenInternalCompilerData(
32+
compilerData: KLoggingEventBuilder.InternalCompilerData
33+
) {
34+
internalCompilerData = compilerData
35+
}
36+
37+
@Deprecated(
38+
message = "This is an internal API and should not be used by user code",
39+
level = DeprecationLevel.HIDDEN,
40+
)
41+
@Suppress("kotlin:S1133")
42+
public fun KLogger.entryWithCompilerData(
43+
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
44+
vararg arguments: Any?,
45+
): Unit = atTrace {
46+
message = "entry(${arguments.joinToString()})"
47+
internalCompilerData = compilerData
48+
}
49+
50+
@Deprecated(
51+
message = "This is an internal API and should not be used by user code",
52+
level = DeprecationLevel.HIDDEN,
53+
)
54+
@Suppress("kotlin:S1133")
55+
public fun KLogger.exitWithCompilerData(
56+
compilerData: KLoggingEventBuilder.InternalCompilerData? = null
57+
): Unit = atTrace {
58+
message = "exit"
59+
internalCompilerData = compilerData
60+
}
61+
62+
@Deprecated(
63+
message = "This is an internal API and should not be used by user code",
64+
level = DeprecationLevel.HIDDEN,
65+
)
66+
@Suppress("kotlin:S1133")
67+
public fun <T> KLogger.exitWithCompilerData(
68+
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
69+
result: T,
70+
): T where T : Any? {
71+
atTrace {
72+
message = "exit($result)"
73+
internalCompilerData = compilerData
74+
}
75+
return result
76+
}
77+
78+
@Deprecated(
79+
message = "This is an internal API and should not be used by user code",
80+
level = DeprecationLevel.HIDDEN,
81+
)
82+
@Suppress("kotlin:S1133")
83+
public fun <T> KLogger.throwingWithCompilerData(
84+
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
85+
throwable: T,
86+
): T where T : Throwable {
87+
atError {
88+
cause = throwable
89+
message = "throwing($throwable)"
90+
internalCompilerData = compilerData
91+
}
92+
return throwable
93+
}
94+
95+
@Deprecated(
96+
message = "This is an internal API and should not be used by user code",
97+
level = DeprecationLevel.HIDDEN,
98+
)
99+
@Suppress("kotlin:S1133")
100+
public fun <T> KLogger.catchingWithCompilerData(
101+
compilerData: KLoggingEventBuilder.InternalCompilerData? = null,
102+
throwable: T,
103+
) where T : Throwable {
104+
atError {
105+
cause = throwable
106+
message = "catching($throwable)"
107+
internalCompilerData = compilerData
108+
}
109+
}

src/jvmMain/kotlin/io/github/oshai/kotlinlogging/logback/internal/LogbackLoggerFactory.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ch.qos.logback.classic.LoggerContext
55
import ch.qos.logback.classic.spi.LogbackServiceProvider
66
import io.github.oshai.kotlinlogging.KLogger
77

8-
internal object LogbackLoggerFactory {
8+
public object LogbackLoggerFactory {
99

1010
private val logbackServiceProvider = createLogbackServiceProvider()
1111

@@ -22,5 +22,6 @@ internal object LogbackLoggerFactory {
2222
internal fun wrapLogbackLogger(logbackLogger: Logger): KLogger =
2323
LogbackLoggerWrapper(logbackLogger, logbackServiceProvider)
2424

25-
fun getLoggerContext() = logbackServiceProvider.loggerFactory as LoggerContext
25+
public fun getLoggerContext(): LoggerContext =
26+
logbackServiceProvider.loggerFactory as LoggerContext
2627
}

0 commit comments

Comments
 (0)