Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f44daf99 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

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
parent 68307f0d
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2023 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -14,25 +14,13 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package com.android.protolog.tool
package com.android.internal.protolog.common;


import com.github.javaparser.ast.Node
public enum LogLevel {
    DEBUG("d"), VERBOSE("v"), INFO("i"), WARN("w"), ERROR("e"), WTF("wtf");


enum class LogLevel {
    public final String shortCode;
    DEBUG, VERBOSE, INFO, WARN, ERROR, WTF;
    LogLevel(String shortCode) {

        this.shortCode = shortCode;
    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)
            }
        }
    }
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.protolog.tool
package com.android.protolog.tool


import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.ImportDeclaration
import com.github.javaparser.ast.ImportDeclaration
import com.github.javaparser.ast.expr.BinaryExpr
import com.github.javaparser.ast.expr.BinaryExpr
+18 −1
Original line number Original line Diff line number Diff line
@@ -16,7 +16,9 @@


package com.android.protolog.tool
package com.android.protolog.tool


import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.ast.CompilationUnit
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.Expression
import com.github.javaparser.ast.expr.FieldAccessExpr
import com.github.javaparser.ast.expr.FieldAccessExpr
import com.github.javaparser.ast.expr.MethodCallExpr
import com.github.javaparser.ast.expr.MethodCallExpr
@@ -105,9 +107,24 @@ open class ProtoLogCallProcessor(
                                "- not a ProtoLogGroup enum member: $call", context)
                                "- 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))
                            call.name.toString(), call, context), groupMap.getValue(groupName))
                }
                }
        return code
        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)
            }
        }
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.protolog.tool
package com.android.protolog.tool


import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.ast.expr.MethodCallExpr
import com.github.javaparser.ast.expr.MethodCallExpr


interface ProtoLogCallVisitor {
interface ProtoLogCallVisitor {
+1 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.protolog.tool
package com.android.protolog.tool


import com.android.internal.protolog.common.LogDataType
import com.android.internal.protolog.common.LogDataType
import com.android.internal.protolog.common.LogLevel
import com.github.javaparser.StaticJavaParser
import com.github.javaparser.StaticJavaParser
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.CompilationUnit
import com.github.javaparser.ast.NodeList
import com.github.javaparser.ast.NodeList
Loading