summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pablo Gamito <pablogamito@google.com> 2024-02-22 14:24:52 +0000
committer Pablo Gamito <pablogamito@google.com> 2024-02-22 15:40:01 +0000
commitf44daf993b82cbe817dc7aaf514554cf91350561 (patch)
tree5c9b12d51559abcea490c52a81efd4318f3bf1b3
parent68307f0daeb9b89afcc8e00d09c53294f1ee954d (diff)
Extract LogLevel to common package
Since we now use it in a few different places including in the ProtoLogTool. Flag: ACONFIG android.tracing.Flags.perfettoProtolog DEVELOPMENT Bug: 276432490 Test: atest FrameworksServicesTests Change-Id: Iba3a4904ea0b5e27afb1486c765e627fb343f6af
-rw-r--r--core/java/com/android/internal/protolog/common/LogLevel.java26
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt1
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/LogLevel.kt38
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt19
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ProtoLogCallVisitor.kt1
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt1
-rw-r--r--tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt1
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt1
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt1
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt1
-rw-r--r--tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt1
11 files changed, 52 insertions, 39 deletions
diff --git a/core/java/com/android/internal/protolog/common/LogLevel.java b/core/java/com/android/internal/protolog/common/LogLevel.java
new file mode 100644
index 000000000000..16c34e1f333e
--- /dev/null
+++ b/core/java/com/android/internal/protolog/common/LogLevel.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.protolog.common;
+
+public enum LogLevel {
+ DEBUG("d"), VERBOSE("v"), INFO("i"), WARN("w"), ERROR("e"), WTF("wtf");
+
+ public final String shortCode;
+ LogLevel(String shortCode) {
+ this.shortCode = shortCode;
+ }
+}
diff --git a/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt b/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt
index 451e514b8b33..07c6fd328318 100644
--- a/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/CodeUtils.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.ImportDeclaration
import com.github.javaparser.ast.expr.BinaryExpr
diff --git a/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt b/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt
deleted file mode 100644
index e88f0f8231bd..000000000000
--- a/tools/protologtool/src/com/android/protolog/tool/LogLevel.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.protolog.tool
-
-import com.github.javaparser.ast.Node
-
-enum class LogLevel {
- DEBUG, VERBOSE, INFO, WARN, ERROR, WTF;
-
- companion object {
- fun getLevelForMethodName(name: String, node: Node, context: ParsingContext): LogLevel {
- return when (name) {
- "d" -> DEBUG
- "v" -> VERBOSE
- "i" -> INFO
- "w" -> WARN
- "e" -> ERROR
- "wtf" -> WTF
- else ->
- throw InvalidProtoLogCallException("Unknown log level $name in $node", context)
- }
- }
- }
-}
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt
index 2181cf680f6c..9a76a6f84c2b 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallProcessor.kt
@@ -16,7 +16,9 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.ast.CompilationUnit
+import com.github.javaparser.ast.Node
import com.github.javaparser.ast.expr.Expression
import com.github.javaparser.ast.expr.FieldAccessExpr
import com.github.javaparser.ast.expr.MethodCallExpr
@@ -105,9 +107,24 @@ open class ProtoLogCallProcessor(
"- not a ProtoLogGroup enum member: $call", context)
}
- callVisitor?.processCall(call, messageString, LogLevel.getLevelForMethodName(
+ callVisitor?.processCall(call, messageString, getLevelForMethodName(
call.name.toString(), call, context), groupMap.getValue(groupName))
}
return code
}
+
+ companion object {
+ fun getLevelForMethodName(name: String, node: Node, context: ParsingContext): LogLevel {
+ return when (name) {
+ "d" -> LogLevel.DEBUG
+ "v" -> LogLevel.VERBOSE
+ "i" -> LogLevel.INFO
+ "w" -> LogLevel.WARN
+ "e" -> LogLevel.ERROR
+ "wtf" -> LogLevel.WTF
+ else ->
+ throw InvalidProtoLogCallException("Unknown log level $name in $node", context)
+ }
+ }
+ }
}
diff --git a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallVisitor.kt b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallVisitor.kt
index aa58b69d61cb..8cd927a7cd0e 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallVisitor.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ProtoLogCallVisitor.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.ast.expr.MethodCallExpr
interface ProtoLogCallVisitor {
diff --git a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt
index 27e61a139451..b50f357c57ec 100644
--- a/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/SourceTransformer.kt
@@ -17,6 +17,7 @@
package com.android.protolog.tool
import com.android.internal.protolog.common.LogDataType
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.StaticJavaParser
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.NodeList
diff --git a/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt b/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt
index 175c71ff810b..0d5d022959b2 100644
--- a/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/ViewerConfigBuilder.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.android.json.stream.JsonWriter
import com.github.javaparser.ast.CompilationUnit
import com.android.protolog.tool.Constants.VERSION
diff --git a/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt b/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt
index b916f8f00a68..b08d859bad32 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/CodeUtilsTest.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.StaticJavaParser
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.StringLiteralExpr
diff --git a/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt b/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt
index 97f67a0a3fdb..90b8059dae1c 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/ProtoLogCallProcessorTest.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.StaticJavaParser
import com.github.javaparser.ast.expr.MethodCallExpr
import org.junit.Assert.assertEquals
diff --git a/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt b/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt
index 4f2be328fc8a..f52bfeccea51 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/SourceTransformerTest.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.StaticJavaParser
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.expr.MethodCallExpr
diff --git a/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt b/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt
index a24761aed9db..52dce21944f6 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/ViewerConfigBuilderTest.kt
@@ -16,6 +16,7 @@
package com.android.protolog.tool
+import com.android.internal.protolog.common.LogLevel
import com.android.json.stream.JsonReader
import com.android.protolog.tool.ViewerConfigBuilder.LogCall
import org.junit.Assert.assertEquals