mirror of
https://github.com/NixOS/nix
synced 2025-06-27 16:51:15 +02:00
move showTrace to new loggerSettings
This commit is contained in:
parent
5ae498872a
commit
bf2788e4c1
10 changed files with 35 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "logging.hh"
|
||||
#include "util.hh"
|
||||
#include "config.hh"
|
||||
|
||||
#include <atomic>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
@ -7,6 +8,10 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
LoggerSettings loggerSettings;
|
||||
|
||||
static GlobalConfig::Register r1(&loggerSettings);
|
||||
|
||||
static thread_local ActivityId curActivity = 0;
|
||||
|
||||
ActivityId getCurActivity()
|
||||
|
@ -18,7 +23,7 @@ void setCurActivity(const ActivityId activityId)
|
|||
curActivity = activityId;
|
||||
}
|
||||
|
||||
Logger * logger = makeSimpleLogger(true, false);
|
||||
Logger * logger = makeSimpleLogger(true);
|
||||
|
||||
void Logger::warn(const std::string & msg)
|
||||
{
|
||||
|
@ -36,10 +41,9 @@ public:
|
|||
|
||||
bool systemd, tty;
|
||||
bool printBuildLogs;
|
||||
bool showTrace;
|
||||
|
||||
SimpleLogger(bool printBuildLogs, bool showTrace)
|
||||
: printBuildLogs(printBuildLogs), showTrace(showTrace)
|
||||
SimpleLogger(bool printBuildLogs)
|
||||
: printBuildLogs(printBuildLogs)
|
||||
{
|
||||
systemd = getEnv("IN_SYSTEMD") == "1";
|
||||
tty = isatty(STDERR_FILENO);
|
||||
|
@ -49,13 +53,6 @@ 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;
|
||||
|
@ -80,7 +77,7 @@ public:
|
|||
void logEI(const ErrorInfo & ei) override
|
||||
{
|
||||
std::stringstream oss;
|
||||
showErrorInfo(oss, ei, showTrace);
|
||||
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||
|
||||
log(ei.level, oss.str());
|
||||
}
|
||||
|
@ -129,9 +126,9 @@ void writeToStderr(const string & s)
|
|||
}
|
||||
}
|
||||
|
||||
Logger * makeSimpleLogger(bool printBuildLogs, bool showTrace)
|
||||
Logger * makeSimpleLogger(bool printBuildLogs)
|
||||
{
|
||||
return new SimpleLogger(printBuildLogs, showTrace);
|
||||
return new SimpleLogger(printBuildLogs);
|
||||
}
|
||||
|
||||
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
|
||||
|
@ -152,13 +149,6 @@ 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;
|
||||
|
@ -189,7 +179,7 @@ struct JSONLogger : Logger {
|
|||
void logEI(const ErrorInfo & ei) override
|
||||
{
|
||||
std::ostringstream oss;
|
||||
showErrorInfo(oss, ei, getShowTrace());
|
||||
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||
|
||||
nlohmann::json json;
|
||||
json["action"] = "msg";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue