Skip to content

Commit ce1afff

Browse files
Merge pull request #1408 from square/sedwards/update-logging-visibility
Make Logging Utils Public
2 parents 82fda25 + f702c2c commit ce1afff

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

workflow-tracing/api/workflow-tracing.api

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,17 @@ public final class com/squareup/workflow1/tracing/RenderPassInfo {
8686
}
8787

8888
public final class com/squareup/workflow1/tracing/RuntimeLoggingUtilsKt {
89+
public static final fun getWfHumanClassName (Ljava/lang/Object;)Ljava/lang/String;
8990
public static final fun getWfLogString (Ljava/lang/Object;)Ljava/lang/String;
9091
public static final fun toLoggingShortName (Lcom/squareup/workflow1/WorkflowAction;)Ljava/lang/String;
9192
public static final fun toWfLoggingName (Lcom/squareup/workflow1/WorkflowAction;)Ljava/lang/String;
93+
public static final fun toWfLoggingName (Lcom/squareup/workflow1/WorkflowIdentifier;)Ljava/lang/String;
94+
public static final fun toWfLoggingName (Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;)Ljava/lang/String;
95+
public static final fun toWfLoggingName (Lkotlin/reflect/KClass;)Ljava/lang/String;
96+
public static final fun toWfLoggingName (Lkotlin/reflect/KType;)Ljava/lang/String;
97+
public static final fun wfEllipsizeEnd (Ljava/lang/String;I)Ljava/lang/String;
98+
public static final fun wfRemoveReflectionNotAvailable (Ljava/lang/String;)Ljava/lang/String;
99+
public static final fun wfStripSquarePackage (Ljava/lang/String;)Ljava/lang/String;
92100
public static final fun workerKey (Ljava/lang/String;)Ljava/lang/String;
93101
}
94102

workflow-tracing/src/main/java/com/squareup/workflow1/tracing/RuntimeLoggingUtils.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
99
import kotlin.reflect.KClass
1010
import kotlin.reflect.KType
1111

12-
internal fun WorkflowSession.toWfLoggingName(): String {
12+
/**
13+
* Short name that can be used for logs that has the [identifier] logged as well
14+
* as the key.
15+
*/
16+
public fun WorkflowSession.toWfLoggingName(): String {
1317
val renderKey = renderKey
1418
return if (renderKey.isEmpty()) {
1519
identifier.toWfLoggingName()
@@ -18,7 +22,11 @@ internal fun WorkflowSession.toWfLoggingName(): String {
1822
}
1923
}
2024

21-
internal fun WorkflowIdentifier.toWfLoggingName(): String {
25+
/**
26+
* Short name that for the identifier that can be used for logs. This reports
27+
* the 'log name' of the class.
28+
*/
29+
public fun WorkflowIdentifier.toWfLoggingName(): String {
2230
return when (val type = realType) {
2331
is Snapshottable -> type.kClass?.toWfLoggingName() ?: type.typeName
2432
is Unsnapshottable -> type.kType.toWfLoggingName()
@@ -55,7 +63,10 @@ public fun String.workerKey(): String {
5563
}
5664
}
5765

58-
internal fun KType.toWfLoggingName(): String {
66+
/**
67+
* Reasonable log name based on type.
68+
*/
69+
public fun KType.toWfLoggingName(): String {
5970
if (classifier == null) return toString().wfStripSquarePackage()
6071

6172
val classifierName = when (val c = classifier) {
@@ -79,7 +90,7 @@ internal fun KType.toWfLoggingName(): String {
7990
*
8091
* For example, `java.util.Map` would be `Map`, and `java.util.Map.Entry` would be `Map.Entry`.
8192
*/
82-
internal fun getWfHumanClassName(obj: Any): String {
93+
public fun getWfHumanClassName(obj: Any): String {
8394
val objClass: Class<*> = when (obj) {
8495
is KClass<*> -> obj.java
8596
is Class<*> -> obj
@@ -98,7 +109,10 @@ internal fun getWfHumanClassName(obj: Any): String {
98109
return humanName
99110
}
100111

101-
internal fun KClass<*>.toWfLoggingName(): String {
112+
/**
113+
* Reasonable class name based on type.
114+
*/
115+
public fun KClass<*>.toWfLoggingName(): String {
102116
return getWfHumanClassName(this)
103117
}
104118

@@ -134,7 +148,7 @@ public fun getWfLogString(log: Any?): String {
134148
* @param maxLength The maximum length the string can be before ellipsizing will occur. This must be
135149
* a positive number.
136150
*/
137-
internal fun String.wfEllipsizeEnd(maxLength: Int): String {
151+
public fun String.wfEllipsizeEnd(maxLength: Int): String {
138152
require(maxLength > 0)
139153

140154
return if (maxLength < length) {
@@ -147,7 +161,7 @@ internal fun String.wfEllipsizeEnd(maxLength: Int): String {
147161
/**
148162
* Removes the string from kotlin.jvm.internal.Reflection#REFLECTION_NOT_AVAILABLE
149163
*/
150-
internal fun String.wfRemoveReflectionNotAvailable() = replace(
164+
public fun String.wfRemoveReflectionNotAvailable() = replace(
151165
" (Kotlin reflection is not available)",
152166
""
153167
)
@@ -158,7 +172,7 @@ internal fun String.wfRemoveReflectionNotAvailable() = replace(
158172
*
159173
* This will help make things more readable for classes within this library.
160174
*/
161-
internal fun String.wfStripSquarePackage(): String {
175+
public fun String.wfStripSquarePackage(): String {
162176
// Find the index of every "com.squareup".
163177
var cursor = 0
164178
var packages: MutableList<Int>? = null

0 commit comments

Comments
 (0)