base: Add default log functionality to Logger

The only difference between the NormalLogger and Logger is
a simple implementation for log(), which is then called by
the other loggers. Since this is common to everybody, move
this implementation to Logger and remove NormalLogger.

This makes it possible to test the NormalLoggers using the
current gtest logging framework.

Change-Id: I6805fa14f58ddc7d37b00fcd7fcacb32e0b5d456
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41395
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
This commit is contained in:
Daniel R. Carvalho
2021-02-14 11:03:57 -03:00
committed by Daniel Carvalho
parent 763239ac32
commit 6bbee0fbce
2 changed files with 7 additions and 15 deletions

View File

@@ -46,27 +46,18 @@
namespace {
class NormalLogger : public Logger
class ExitLogger : public Logger
{
public:
using Logger::Logger;
protected:
void log(const Loc &loc, std::string s) override { std::cerr << s; }
};
class ExitLogger : public NormalLogger
{
public:
using NormalLogger::NormalLogger;
protected:
void
log(const Loc &loc, std::string s) override
{
std::stringstream ss;
ccprintf(ss, "Memory Usage: %ld KBytes\n", memUsage());
NormalLogger::log(loc, s + ss.str());
Logger::log(loc, s + ss.str());
}
};
@@ -81,9 +72,9 @@ class FatalLogger : public ExitLogger
ExitLogger panicLogger("panic: ");
FatalLogger fatalLogger("fatal: ");
NormalLogger warnLogger("warn: ");
NormalLogger infoLogger("info: ");
NormalLogger hackLogger("hack: ");
Logger warnLogger("warn: ");
Logger infoLogger("info: ");
Logger hackLogger("hack: ");
} // anonymous namespace

View File

@@ -122,7 +122,8 @@ class Logger
protected:
bool enabled;
virtual void log(const Loc &loc, std::string s) = 0;
/** Generates the log message. By default it is sent to cerr. */
virtual void log(const Loc &loc, std::string s) { std::cerr << s; }
virtual void exit() { /* Fall through to the abort in exit_helper. */ }
const char *prefix;