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

Commit acb832c7 authored by chenbruce's avatar chenbruce
Browse files

[Resolver-log] Replacing unused debuging functions by LOG(x).

Removing printf/vlog/syslog/ ...etc debuging functions and using LOG(x).
Then we can configure the log verbosity in the resolver with:
// Set the minimum severity level for logging, returning the old severity.
LogSeverity SetMinimumLogSeverity(LogSeverity new_severity);

Bug: 121176138
Test: make; flash;
Test: The default severity is WARNING. Reboot device and check that only
      WARNING/ERROR logs are printed.
Change-Id: Ib8de89a4cba96ded186579ccefaf88031066e508
parent 64b4ff09
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <vector>

#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android/multinetwork.h>  // ResNsendFlags
#include <cutils/misc.h>           // FIRST_APPLICATION_UID
@@ -56,6 +57,7 @@
#include "Stopwatch.h"
#include "netd_resolv/stats.h"  // RCODE_TIMEOUT
#include "netdutils/InternetAddresses.h"
#include "resolv_private.h"
#include "thread_util.h"

using aidl::android::net::metrics::INetdEventListener;
@@ -66,6 +68,9 @@ bool resolv_init(const dnsproxylistener_callbacks& callbacks) {
    android::base::InitLogging(/*argv=*/nullptr);
    android::base::SetDefaultTag("libnetd_resolv");
    ALOGI("Initializing resolver");
    const std::string logSeverityStr =
            android::base::GetProperty("persist.sys.nw_dns_resolver_log", "WARNING");
    android::base::SetMinimumLogSeverity(logSeverityStrToEnum(logSeverityStr));

    if (!gDnsProxyListener.setCallbacks(callbacks)) {
        ALOGE("Unable to set callbacks to DnsProxyListener");
+14 −25
Original line number Diff line number Diff line
@@ -49,9 +49,10 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <syslog.h>
#include <unistd.h>

#include <android-base/logging.h>

#include "netd_resolv/resolv.h"
#include "resolv_cache.h"
#include "resolv_private.h"
@@ -798,8 +799,6 @@ trynumeric:

/* code duplicate with gethnamaddr.c */

static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\"";

#define BOUNDED_INCR(x)      \
    do {                     \
        BOUNDS_CHECK(cp, x); \
@@ -931,9 +930,9 @@ static struct addrinfo* getanswer(const querybuf* answer, int anslen, const char
            }
        } else if (type != qtype) {
            if (type != T_KEY && type != T_SIG)
                syslog(LOG_NOTICE | LOG_AUTH,
                       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", qname,
                       p_class(C_IN), p_type(qtype), p_type(type));
                LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
                           << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
                           << p_type(type) << "\"";
            cp += n;
            continue; /* XXX - had_error++ ? */
        }
@@ -941,7 +940,8 @@ static struct addrinfo* getanswer(const querybuf* answer, int anslen, const char
            case T_A:
            case T_AAAA:
                if (strcasecmp(canonname, bp) != 0) {
                    syslog(LOG_NOTICE | LOG_AUTH, AskedForGot, canonname, bp);
                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << canonname
                               << "\", got \"" << bp << "\"";
                    cp += n;
                    continue; /* XXX - had_error++ ? */
                }
@@ -1605,17 +1605,14 @@ static int res_queryN(const char* name, res_target* target, res_state res, int*
        int type = t->qtype;
        answer = t->answer;
        anslen = t->anslen;
#ifdef DEBUG
        if (res->options & RES_DEBUG) printf(";; res_queryN(%s, %d, %d)\n", name, cl, type);
#endif

        LOG(DEBUG) << ";; res_queryN(" << name << ", " << cl << " , " << type << ")";

        n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
        if (n > 0 && (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 && !retried)
            n = res_nopt(res, n, buf, sizeof(buf), anslen);
        if (n <= 0) {
#ifdef DEBUG
            if (res->options & RES_DEBUG) printf(";; res_queryN: mkquery failed\n");
#endif
            LOG(DEBUG) << ";; res_queryN: mkquery failed";
            *herrno = NO_RECOVERY;
            return n;
        }
@@ -1628,16 +1625,11 @@ static int res_queryN(const char* name, res_target* target, res_state res, int*
            /* if the query choked with EDNS0, retry without EDNS0 */
            if ((res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 &&
                (res->_flags & RES_F_EDNS0ERR) && !retried) {
#ifdef DEBUG
                if (res->options & RES_DEBUG) printf(";; res_queryN: retry without EDNS0\n");
#endif
                LOG(DEBUG) << ";; res_queryN: retry without EDNS0";
                retried = true;
                goto again;
            }
#ifdef DEBUG
            if (res->options & RES_DEBUG)
                printf(";; rcode = %u, ancount=%u\n", hp->rcode, ntohs(hp->ancount));
#endif
            LOG(DEBUG) << ";; rcode = " << hp->rcode << ", ancount=" << ntohs(hp->ancount);
            continue;
        }

@@ -1815,12 +1807,8 @@ static int res_querydomainN(const char* name, const char* domain, res_target* ta

    assert(name != NULL);
    /* XXX: target may be NULL??? */

#ifdef DEBUG
    if (res->options & RES_DEBUG)
        printf(";; res_querydomain(%s, %s)\n", name, domain ? domain : "<Nil>");
#endif
    if (domain == NULL) {
        LOG(DEBUG) << ";; res_querydomain(" << name << ", <Nil>)";
        /*
         * Check for trailing '.';
         * copy without '.' if present.
@@ -1836,6 +1824,7 @@ static int res_querydomainN(const char* name, const char* domain, res_target* ta
        } else
            longname = name;
    } else {
        LOG(DEBUG) << ";; res_querydomain(" << name << ", " << domain << ")";
        n = strlen(name);
        d = strlen(domain);
        if (n + 1 + d + 1 > sizeof(nbuf)) {
+13 −40
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@
 * --Copyright--
 */

#include <android-base/logging.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <assert.h>
@@ -67,7 +68,6 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <syslog.h>
#include <unistd.h>
#include <functional>
#include <vector>
@@ -87,17 +87,10 @@
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)

#ifndef LOG_AUTH
#define LOG_AUTH 0
#endif


#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || (ok)(nm) != 0)
#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)

static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\"";

#define MAXPACKET (8 * 1024)

typedef union {
@@ -110,9 +103,6 @@ typedef union {
    char ac;
} align;

#ifdef DEBUG
static void debugprintf(const char*, res_state, ...) __attribute__((__format__(__printf__, 1, 3)));
#endif
static struct hostent* getanswer(const querybuf*, int, const char*, int, res_state, struct hostent*,
                                 char*, size_t, int*);
static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
@@ -138,25 +128,6 @@ static int android_gethostbyaddrfornetcontext_proxy(const void* addr, socklen_t
                                                    const struct android_net_context* netcontext,
                                                    hostent** hp);

#ifdef DEBUG
static void debugprintf(const char* msg, res_state res, ...) {
    _DIAGASSERT(msg != NULL);

    if (res->options & RES_DEBUG) {
        int save = errno;
        va_list ap;

        va_start(ap, res);
        vprintf(msg, ap);
        va_end(ap);

        errno = save;
    }
}
#else
#define debugprintf(msg, res, num) /*nada*/
#endif

#define BOUNDED_INCR(x)      \
    do {                     \
        BOUNDS_CHECK(cp, x); \
@@ -306,16 +277,17 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
        }
        if (type != qtype) {
            if (type != T_KEY && type != T_SIG)
                syslog(LOG_NOTICE | LOG_AUTH,
                       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", qname,
                       p_class(C_IN), p_type(qtype), p_type(type));
                LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << " "
                           << p_class(C_IN) << " " << p_type(qtype) << "\", got type \""
                           << p_type(type) << "\"";
            cp += n;
            continue; /* XXX - had_error++ ? */
        }
        switch (type) {
            case T_PTR:
                if (strcasecmp(tname, bp) != 0) {
                    syslog(LOG_NOTICE | LOG_AUTH, AskedForGot, qname, bp);
                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << qname << "\", got \""
                               << bp << "\"";
                    cp += n;
                    continue; /* XXX - had_error++ ? */
                }
@@ -342,7 +314,8 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
            case T_A:
            case T_AAAA:
                if (strcasecmp(hent->h_name, bp) != 0) {
                    syslog(LOG_NOTICE | LOG_AUTH, AskedForGot, hent->h_name, bp);
                    LOG(DEBUG) << __func__ << "(getanswer): asked for \"" << hent->h_name
                               << "\", got \"" << bp << "\"";
                    cp += n;
                    continue; /* XXX - had_error++ ? */
                }
@@ -369,13 +342,13 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
                bp += sizeof(align) - (size_t)((u_long) bp % sizeof(align));

                if (bp + n >= ep) {
                    debugprintf("size (%d) too big\n", res, n);
                    LOG(DEBUG) << "size (" << n << ") too big";
                    had_error++;
                    continue;
                }
                if (hap >= &addr_ptrs[MAXADDRS - 1]) {
                    if (!toobig++) {
                        debugprintf("Too many addresses (%d)\n", res, MAXADDRS);
                        LOG(DEBUG) << "Too many addresses (" << MAXADDRS << ")";
                    }
                    cp += n;
                    continue;
@@ -820,7 +793,7 @@ static int _dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
    n = res_nsearch(res, name, C_IN, type, buf->buf, (int) sizeof(buf->buf), &herrno);
    if (n < 0) {
        free(buf);
        debugprintf("res_nsearch failed (%d)\n", res, n);
        LOG(DEBUG) << "res_nsearch failed (" << n << ")";
        // Pass herrno to catch more detailed errors rather than EAI_NODATA.
        return herrnoToAiErrno(herrno);
    }
@@ -885,7 +858,7 @@ static int _dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
    n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int) sizeof(buf->buf), &herrno);
    if (n < 0) {
        free(buf);
        debugprintf("res_nquery failed (%d)\n", res, n);
        LOG(DEBUG) << "res_nquery failed (" << n << ")";
        return herrnoToAiErrno(herrno);
    }
    hp = getanswer(buf, n, qbuf, T_PTR, res, info->hp, info->buf, info->buflen, &herrno);
+62 −100

File changed.

Preview size limit exceeded, changes collapsed.

+111 −52
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@
#include <arpa/nameser.h>
#include <netinet/in.h>

#include <android-base/logging.h>
#include <ctype.h>
#include <errno.h>
#include <math.h>
@@ -121,12 +122,34 @@ struct res_sym {
    const char* humanname; /* Its fun name, like "mail exchanger" */
};

static void do_section(const res_state statp, ns_msg* handle, ns_sect section, int pflag,
                       FILE* file) {
/* add a formatted string to a bounded buffer */
static char* dbprint(char* p, char* end, const char* format, ...) {
    int avail, n;
    va_list args;

    avail = end - p;

    if (avail <= 0) return p;

    va_start(args, format);
    n = vsnprintf(p, avail, format, args);
    va_end(args);

    /* certain C libraries return -1 in case of truncation */
    if (n < 0 || n > avail) n = avail;

    p += n;
    /* certain C libraries do not zero-terminate in case of truncation */
    if (p == end) p[-1] = 0;

    return p;
}
static void do_section(const res_state statp, ns_msg* handle, ns_sect section, int pflag) {
    int n, sflag, rrnum;
    int buflen = 2048;
    ns_opcode opcode;
    ns_rr rr;
    char temp[2048], *p = temp, *end = p + sizeof(temp);

    /*
     * Print answer records.
@@ -136,7 +159,8 @@ static void do_section(const res_state statp, ns_msg* handle, ns_sect section, i

    char* buf = (char*) malloc((size_t) buflen);
    if (buf == NULL) {
        fprintf(file, ";; memory allocation failure\n");
        dbprint(p, end, ";; memory allocation failure\n");
        LOG(VERBOSE) << temp;
        return;
    }

@@ -145,23 +169,23 @@ static void do_section(const res_state statp, ns_msg* handle, ns_sect section, i
    for (;;) {
        if (ns_parserr(handle, section, rrnum, &rr)) {
            if (errno != ENODEV)
                fprintf(file, ";; ns_parserr: %s\n", strerror(errno));
                dbprint(p, end, ";; ns_parserr: %s", strerror(errno));
            else if (rrnum > 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
                putc('\n', file);
                dbprint(p, end, "\n");
            goto cleanup;
        }
        if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
            fprintf(file, ";; %s SECTION:\n", p_section(section, opcode));
            dbprint(p, end, ";; %s SECTION:\n", p_section(section, opcode));
        if (section == ns_s_qd)
            fprintf(file, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr), p_type(ns_rr_type(rr)),
                    p_class(ns_rr_class(rr)));
            dbprint(p, end, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr),
                    p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr)));
        else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
            size_t rdatalen, ttl;
            uint16_t optcode, optlen;

            rdatalen = ns_rr_rdlen(rr);
            ttl = ns_rr_ttl(rr);
            fprintf(file, "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl >> 16) & 0xff,
            dbprint(p, end, "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl >> 16) & 0xff,
                    ns_rr_class(rr), ttl & 0xffff);
            while (rdatalen >= 4) {
                const u_char* cp = ns_rr_rdata(rr);
@@ -171,27 +195,33 @@ static void do_section(const res_state statp, ns_msg* handle, ns_sect section, i
                GETSHORT(optlen, cp);

                if (optcode == NS_OPT_NSID) {
                    fputs("; NSID: ", file);
                    p = dbprint(p, end, "; NSID: ");
                    if (optlen == 0) {
                        fputs("; NSID\n", file);
                        p = dbprint(p, end, "; NSID\n");
                    } else {
                        fputs("; NSID: ", file);
                        for (i = 0; i < optlen; i++) fprintf(file, "%02x ", cp[i]);
                        fputs(" (", file);
                        for (i = 0; i < optlen; i++)
                            fprintf(file, "%c", isprint(cp[i]) ? cp[i] : '.');
                        fputs(")\n", file);
                        p = dbprint(p, end, "; NSID: ");
                        for (i = 0; i < optlen; i++) {
                            p = dbprint(p, end, "%02x ", cp[i]);
                        }
                        p = dbprint(p, end, " (");
                        for (i = 0; i < optlen; i++) {
                            p = dbprint(p, end, "%c", isprint(cp[i]) ? cp[i] : '.');
                        }
                        p = dbprint(p, end, ")\n");
                    }
                } else {
                    if (optlen == 0) {
                        fprintf(file, "; OPT=%u\n", optcode);
                        p = dbprint(p, end, "; OPT=%u\n", optcode);
                    } else {
                        fprintf(file, "; OPT=%u: ", optcode);
                        for (i = 0; i < optlen; i++) fprintf(file, "%02x ", cp[i]);
                        fputs(" (", file);
                        for (i = 0; i < optlen; i++)
                            fprintf(file, "%c", isprint(cp[i]) ? cp[i] : '.');
                        fputs(")\n", file);
                        p = dbprint(p, end, "; OPT=%u: ", optcode);
                        for (i = 0; i < optlen; i++) {
                            p = dbprint(p, end, "%02x ", cp[i]);
                        }
                        p = dbprint(p, end, " (");
                        for (i = 0; i < optlen; i++) {
                            p = dbprint(p, end, "%c", isprint(cp[i]) ? cp[i] : '.');
                        }
                        p = dbprint(p, end, ")\n");
                    }
                }
                rdatalen -= 4 + optlen;
@@ -206,34 +236,37 @@ static void do_section(const res_state statp, ns_msg* handle, ns_sect section, i
                        buf = (char*) malloc((size_t)(buflen += 1024));
                    }
                    if (buf == NULL) {
                        fprintf(file, ";; memory allocation failure\n");
                        p = dbprint(p, end, ";; memory allocation failure\n");
                        LOG(VERBOSE) << temp;
                        return;
                    }
                    continue;
                }
                fprintf(file, ";; ns_sprintrr: %s\n", strerror(errno));
                p = dbprint(p, end, ";; ns_sprintrr: %s\n", strerror(errno));
                goto cleanup;
            }
            fputs(buf, file);
            fputc('\n', file);
            p = dbprint(p, end, ";; %s\n", buf);
        }
        rrnum++;
    }
cleanup:
    free(buf);
    LOG(VERBOSE) << temp;
}

/*
 * Print the contents of a query.
 * This is intended to be primarily a debugging routine.
 */
void res_pquery(const res_state statp, const u_char* msg, int len, FILE* file) {

void res_pquery(const res_state statp, const u_char* msg, int len) {
    ns_msg handle;
    int qdcount, ancount, nscount, arcount;
    u_int opcode, rcode, id;
    char temp[2048], *p = temp, *end = p + sizeof(temp);

    if (ns_initparse(msg, len, &handle) < 0) {
        fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
        dbprint(p, end, ";; ns_initparse: %s\n", strerror(errno));
        return;
    }
    opcode = ns_msg_getflag(handle, ns_f_opcode);
@@ -248,37 +281,39 @@ void res_pquery(const res_state statp, const u_char* msg, int len, FILE* file) {
     * Print header fields.
     */
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
        fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", _res_opcodes[opcode],
        dbprint(p, end, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", _res_opcodes[opcode],
                p_rcode((int)rcode), id);
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX)) putc(';', file);
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX)) p = dbprint(p, end, ";");
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
        fprintf(file, "; flags:");
        if (ns_msg_getflag(handle, ns_f_qr)) fprintf(file, " qr");
        if (ns_msg_getflag(handle, ns_f_aa)) fprintf(file, " aa");
        if (ns_msg_getflag(handle, ns_f_tc)) fprintf(file, " tc");
        if (ns_msg_getflag(handle, ns_f_rd)) fprintf(file, " rd");
        if (ns_msg_getflag(handle, ns_f_ra)) fprintf(file, " ra");
        if (ns_msg_getflag(handle, ns_f_z)) fprintf(file, " ??");
        if (ns_msg_getflag(handle, ns_f_ad)) fprintf(file, " ad");
        if (ns_msg_getflag(handle, ns_f_cd)) fprintf(file, " cd");
        p = dbprint(p, end, "; flags:");
        if (ns_msg_getflag(handle, ns_f_qr)) p = dbprint(p, end, " qr");
        if (ns_msg_getflag(handle, ns_f_aa)) p = dbprint(p, end, " aa");
        if (ns_msg_getflag(handle, ns_f_tc)) p = dbprint(p, end, " tc");
        if (ns_msg_getflag(handle, ns_f_rd)) p = dbprint(p, end, " rd");
        if (ns_msg_getflag(handle, ns_f_ra)) p = dbprint(p, end, " ra");
        if (ns_msg_getflag(handle, ns_f_z)) p = dbprint(p, end, " ??");
        if (ns_msg_getflag(handle, ns_f_ad)) p = dbprint(p, end, " ad");
        if (ns_msg_getflag(handle, ns_f_cd)) p = dbprint(p, end, " cd");
    }
    if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
        fprintf(file, "; %s: %d", p_section(ns_s_qd, (int) opcode), qdcount);
        fprintf(file, ", %s: %d", p_section(ns_s_an, (int) opcode), ancount);
        fprintf(file, ", %s: %d", p_section(ns_s_ns, (int) opcode), nscount);
        fprintf(file, ", %s: %d", p_section(ns_s_ar, (int) opcode), arcount);
        p = dbprint(p, end, "; %s: %d", p_section(ns_s_qd, (int)opcode), qdcount);
        p = dbprint(p, end, ", %s: %d", p_section(ns_s_an, (int)opcode), ancount);
        p = dbprint(p, end, ", %s: %d", p_section(ns_s_ns, (int)opcode), nscount);
        p = dbprint(p, end, ", %s: %d", p_section(ns_s_ar, (int)opcode), arcount);
    }
    if ((!statp->pfcode) || (statp->pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
        putc('\n', file);
        p = dbprint(p, end, " \n");
    }
    LOG(VERBOSE) << temp;

    /*
     * Print the various sections.
     */
    do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
    do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
    do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
    do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
    if (qdcount == 0 && ancount == 0 && nscount == 0 && arcount == 0) putc('\n', file);
    do_section(statp, &handle, ns_s_qd, RES_PRF_QUES);
    do_section(statp, &handle, ns_s_an, RES_PRF_ANS);
    do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH);
    do_section(statp, &handle, ns_s_ar, RES_PRF_ADD);
    if (qdcount == 0 && ancount == 0 && nscount == 0 && arcount == 0) LOG(VERBOSE) << ";;";
}

const u_char* p_cdnname(const u_char* cp, const u_char* msg, int len, FILE* file) {
@@ -516,3 +551,27 @@ const char* p_class(int cl) {
const char* p_rcode(int rcode) {
    return (sym_ntos(p_rcode_syms, rcode, (int*) 0));
}

android::base::LogSeverity logSeverityStrToEnum(const std::string& logSeverityStr) {
    android::base::LogSeverity logSeverityEnum;
    if (logSeverityStr == "VERBOSE") {
        logSeverityEnum = android::base::VERBOSE;
    } else if (logSeverityStr == "DEBUG") {
        logSeverityEnum = android::base::DEBUG;
    } else if (logSeverityStr == "INFO") {
        logSeverityEnum = android::base::INFO;
    } else if (logSeverityStr == "WARNING") {
        logSeverityEnum = android::base::WARNING;
    } else if (logSeverityStr == "ERROR") {
        logSeverityEnum = android::base::ERROR;
    } else if (logSeverityStr == "FATAL_WITHOUT_ABORT") {
        logSeverityEnum = android::base::FATAL_WITHOUT_ABORT;
    } else if (logSeverityStr == "FATAL") {
        logSeverityEnum = android::base::FATAL;
    } else {
        // Invalid parameter is treated as WARNING (default setting)
        logSeverityEnum = android::base::WARNING;
    }
    LOG(INFO) << "logSeverityEnum " << logSeverityEnum;
    return logSeverityEnum;
}
Loading