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

Commit f93b4006 authored by Tom Cherry's avatar Tom Cherry
Browse files

logd: use libbase logging

We can use libbase logging to output to the kernel log instead of the
'prdebug' function, so use that instead.

Bonus #1: we can now use CHECK().
Bonus #2: logging unit tests automatically output to stderr.
Bonus #3: We see dependent library's logs instead of losing them to
the void.

Test: logging unit tests
Test: logs show appropriately in dmesg / stderr
Test: CHECK() works
Change-Id: I92f8056b4820dc4998996cf46460568085299700
parent 671f39fd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -217,12 +217,12 @@ LogBufferElementCollection::iterator ChattyLogBuffer::Erase(LogBufferElementColl
    log_id_for_each(i) {
        for (auto b : mLastWorst[i]) {
            if (bad == b.second) {
                android::prdebug("stale mLastWorst[%d] key=%d mykey=%d\n", i, b.first, key);
                LOG(ERROR) << StringPrintf("stale mLastWorst[%d] key=%d mykey=%d", i, b.first, key);
            }
        }
        for (auto b : mLastWorstPidOfSystem[i]) {
            if (bad == b.second) {
                android::prdebug("stale mLastWorstPidOfSystem[%d] pid=%d\n", i, b.first);
                LOG(ERROR) << StringPrintf("stale mLastWorstPidOfSystem[%d] pid=%d", i, b.first);
            }
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#include <string>

#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <cutils/sockets.h>
#include <log/log_properties.h>
@@ -298,7 +299,7 @@ int CommandListener::ReinitCmd::runCommand(SocketClient* cli, int /*argc*/,
                                           char** /*argv*/) {
    setname();

    android::prdebug("logd reinit");
    LOG(INFO) << "logd reinit";
    buf()->Init();
    prune()->init(nullptr);

+0 −8
Original line number Diff line number Diff line
@@ -43,14 +43,6 @@ bool __android_logger_valid_buffer_size(unsigned long) {
}
#endif

void android::prdebug(const char* fmt, ...) {
    va_list ap;
    va_start(ap, fmt);
    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    va_end(ap);
}

char* android::uidToName(uid_t) {
    return nullptr;
}
+3 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include <chrono>

#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <cutils/sockets.h>
#include <private/android_filesystem_config.h>
@@ -201,9 +202,9 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
        }
    }

    android::prdebug(
    LOG(INFO) << android::base::StringPrintf(
            "logdr: UID=%d GID=%d PID=%d %c tail=%lu logMask=%x pid=%d "
            "start=%" PRIu64 "ns deadline=%" PRIi64 "ns\n",
            "start=%" PRIu64 "ns deadline=%" PRIi64 "ns",
            cli->getUid(), cli->getGid(), cli->getPid(), nonBlock ? 'n' : 'b', tail, logMask,
            (int)pid, start.nsec(), static_cast<int64_t>(deadline.time_since_epoch().count()));

+15 −15
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <string>

#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
@@ -115,10 +116,11 @@ bool LogTags::RebuildFileEventLogTags(const char* filename, bool warn) {
    }

    if (warn) {
        android::prdebug(
            ((fd < 0) ? "%s failed to rebuild"
                      : "%s missing, damaged or truncated; rebuilt"),
            filename);
        if (fd < 0) {
            LOG(ERROR) << filename << " failed to rebuild";
        } else {
            LOG(ERROR) << filename << " missing, damaged or truncated; rebuilt";
        }
    }

    if (fd >= 0) {
@@ -182,8 +184,7 @@ void LogTags::AddEventLogTags(uint32_t tag, uid_t uid, const std::string& Name,
        WritePersistEventLogTags(tag, uid, source);
    } else if (warn && !newOne && source) {
        // For the files, we want to report dupes.
        android::prdebug("Multiple tag %" PRIu32 " %s %s %s", tag, Name.c_str(),
                         Format.c_str(), source);
        LOG(DEBUG) << "Multiple tag " << tag << " " << Name << " " << Format << " " << source;
    }
}

@@ -216,7 +217,7 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
                } else if (isdigit(*cp)) {
                    unsigned long Tag = strtoul(cp, &cp, 10);
                    if (warn && (Tag > emptyTag)) {
                        android::prdebug("tag too large %lu", Tag);
                        LOG(WARNING) << "tag too large " << Tag;
                    }
                    while ((cp < endp) && (*cp != '\n') && isspace(*cp)) ++cp;
                    if (cp >= endp) break;
@@ -231,9 +232,8 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
                    std::string Name(name, cp - name);
#ifdef ALLOW_NOISY_LOGGING_OF_PROBLEM_WITH_LOTS_OF_TECHNICAL_DEBT
                    static const size_t maximum_official_tag_name_size = 24;
                    if (warn &&
                        (Name.length() > maximum_official_tag_name_size)) {
                        android::prdebug("tag name too long %s", Name.c_str());
                    if (warn && (Name.length() > maximum_official_tag_name_size)) {
                        LOG(WARNING) << "tag name too long " << Name;
                    }
#endif
                    if (hasAlpha &&
@@ -264,7 +264,7 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
                                        filename, warn);
                    } else {
                        if (warn) {
                            android::prdebug("tag name invalid %.*s",
                            LOG(ERROR) << android::base::StringPrintf("tag name invalid %.*s",
                                                                      (int)(cp - name + 1), name);
                        }
                        lineStart = nullptr;
@@ -276,7 +276,7 @@ void LogTags::ReadFileEventLogTags(const char* filename, bool warn) {
            cp++;
        }
    } else if (warn) {
        android::prdebug("Cannot read %s", filename);
        LOG(ERROR) << "Cannot read " << filename;
    }
}

@@ -479,8 +479,8 @@ uint32_t LogTags::nameToTag_locked(const std::string& name, const char* format,

static int openFile(const char* name, int mode, bool warning) {
    int fd = TEMP_FAILURE_RETRY(open(name, mode));
    if ((fd < 0) && warning) {
        android::prdebug("Failed open %s (%d)", name, errno);
    if (fd < 0 && warning) {
        PLOG(ERROR) << "Failed to open " << name;
    }
    return fd;
}
Loading