1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 11:43:15 +02:00

showTrace flag in loggers

This commit is contained in:
Ben Burdette 2020-06-29 10:20:51 -06:00
parent ef24a0835d
commit 8f81fae116
10 changed files with 60 additions and 20 deletions

View file

@ -26,7 +26,8 @@ const string& BaseError::calcWhat() const
err.name = sname();
std::ostringstream oss;
oss << err;
showErrorInfo(oss, err, false);
// oss << err;
what_ = oss.str();
return *what_;

View file

@ -18,7 +18,7 @@ void setCurActivity(const ActivityId activityId)
curActivity = activityId;
}
Logger * logger = makeSimpleLogger(true);
Logger * logger = makeSimpleLogger(true, false);
void Logger::warn(const std::string & msg)
{
@ -36,9 +36,10 @@ public:
bool systemd, tty;
bool printBuildLogs;
bool showTrace;
SimpleLogger(bool printBuildLogs)
: printBuildLogs(printBuildLogs)
SimpleLogger(bool printBuildLogs, bool showTrace)
: printBuildLogs(printBuildLogs), showTrace(showTrace)
{
systemd = getEnv("IN_SYSTEMD") == "1";
tty = isatty(STDERR_FILENO);
@ -48,6 +49,13 @@ public:
return printBuildLogs;
}
bool getShowTrace() const override {
return showTrace;
}
void setShowTrace(bool showTrace) override {
this->showTrace = showTrace;
}
void log(Verbosity lvl, const FormatOrString & fs) override
{
if (lvl > verbosity) return;
@ -72,7 +80,8 @@ public:
void logEI(const ErrorInfo & ei) override
{
std::stringstream oss;
oss << ei;
showErrorInfo(oss, ei, showTrace);
// oss << ei;
log(ei.level, oss.str());
}
@ -120,9 +129,9 @@ void writeToStderr(const string & s)
}
}
Logger * makeSimpleLogger(bool printBuildLogs)
Logger * makeSimpleLogger(bool printBuildLogs, bool showTrace)
{
return new SimpleLogger(printBuildLogs);
return new SimpleLogger(printBuildLogs, showTrace);
}
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
@ -143,6 +152,13 @@ struct JSONLogger : Logger {
return true;
}
bool getShowTrace() const override {
return prevLogger.getShowTrace();
}
void setShowTrace(bool showTrace) override {
prevLogger.setShowTrace(showTrace);
}
void addFields(nlohmann::json & json, const Fields & fields)
{
if (fields.empty()) return;
@ -173,7 +189,8 @@ struct JSONLogger : Logger {
void logEI(const ErrorInfo & ei) override
{
std::ostringstream oss;
oss << ei;
showErrorInfo(oss, ei, getShowTrace());
// oss << ei;
nlohmann::json json;
json["action"] = "msg";

View file

@ -75,6 +75,9 @@ public:
logEI(ei);
}
virtual bool getShowTrace() const = 0;
virtual void setShowTrace(bool showTrace) = 0;
virtual void warn(const std::string & msg);
virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
@ -146,7 +149,8 @@ struct PushActivity
extern Logger * logger;
Logger * makeSimpleLogger(bool printBuildLogs = true);
Logger * makeSimpleLogger(bool printBuildLogs, bool showTrace);
// Logger * makeSimpleLogger(bool printBuildLogs = true, bool showTrace);
Logger * makeJSONLogger(Logger & prevLogger);

View file

@ -251,7 +251,7 @@ namespace nix {
TEST(addTrace, showTracesWithShowTrace) {
SymbolTable testTable;
ErrorInfo::showTrace = true;
// ErrorInfo::showTrace = true;
auto problem_file = testTable.create(test_file);
auto oneliner_file = testTable.create(one_liner);
@ -275,7 +275,7 @@ namespace nix {
TEST(addTrace, hideTracesWithoutShowTrace) {
SymbolTable testTable;
ErrorInfo::showTrace = false;
// ErrorInfo::showTrace = false;
auto problem_file = testTable.create(test_file);
auto oneliner_file = testTable.create(one_liner);

View file

@ -972,7 +972,7 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
{
auto wrapper = [&]() {
if (!options.allowVfork)
logger = makeSimpleLogger();
logger = makeSimpleLogger(true, false); // TODO remove args.
try {
#if __linux__
if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)