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

Commit f9c767d6 authored by Pablo Gamito's avatar Pablo Gamito Committed by Android (Google) Code Review
Browse files

Merge "Extract LogLevel to common package" into main

parents e62c492c f44daf99
Loading
Loading
Loading
Loading
+26 −0
Original line number 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");
 * you may not use this file except in compliance with the License.
@@ -14,25 +14,13 @@
 * 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 {
    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)
            }
        }
    public final String shortCode;
    LogLevel(String shortCode) {
        this.shortCode = shortCode;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -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
+18 −1
Original line number Diff line number Diff line
@@ -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)
            }
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -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 {
+1 −0
Original line number Diff line number Diff line
@@ -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
Loading