move showTrace to new loggerSettings
This commit is contained in:
parent
5ae498872a
commit
bf2788e4c1
|
@ -1232,7 +1232,7 @@ void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & po
|
||||||
|
|
||||||
/* Evaluate the body. This is conditional on showTrace, because
|
/* Evaluate the body. This is conditional on showTrace, because
|
||||||
catching exceptions makes this function not tail-recursive. */
|
catching exceptions makes this function not tail-recursive. */
|
||||||
if (settings.showTrace)
|
if (loggerSettings.showTrace.get())
|
||||||
try {
|
try {
|
||||||
lambda.body->eval(*this, env2, v);
|
lambda.body->eval(*this, env2, v);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|
|
@ -22,11 +22,11 @@ LogFormat parseLogFormat(const std::string & logFormatStr) {
|
||||||
Logger * makeDefaultLogger() {
|
Logger * makeDefaultLogger() {
|
||||||
switch (defaultLogFormat) {
|
switch (defaultLogFormat) {
|
||||||
case LogFormat::raw:
|
case LogFormat::raw:
|
||||||
return makeSimpleLogger(false, false);
|
return makeSimpleLogger(false);
|
||||||
case LogFormat::rawWithLogs:
|
case LogFormat::rawWithLogs:
|
||||||
return makeSimpleLogger(true, false);
|
return makeSimpleLogger(true);
|
||||||
case LogFormat::internalJson:
|
case LogFormat::internalJson:
|
||||||
return makeJSONLogger(*makeSimpleLogger(true, false));
|
return makeJSONLogger(*makeSimpleLogger(true));
|
||||||
case LogFormat::bar:
|
case LogFormat::bar:
|
||||||
return makeProgressBar();
|
return makeProgressBar();
|
||||||
case LogFormat::barWithLogs:
|
case LogFormat::barWithLogs:
|
||||||
|
|
|
@ -81,14 +81,12 @@ private:
|
||||||
|
|
||||||
bool printBuildLogs;
|
bool printBuildLogs;
|
||||||
bool isTTY;
|
bool isTTY;
|
||||||
bool showTrace;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ProgressBar(bool printBuildLogs, bool isTTY)
|
ProgressBar(bool printBuildLogs, bool isTTY)
|
||||||
: printBuildLogs(printBuildLogs)
|
: printBuildLogs(printBuildLogs)
|
||||||
, isTTY(isTTY)
|
, isTTY(isTTY)
|
||||||
, showTrace(false)
|
|
||||||
{
|
{
|
||||||
state_.lock()->active = isTTY;
|
state_.lock()->active = isTTY;
|
||||||
updateThread = std::thread([&]() {
|
updateThread = std::thread([&]() {
|
||||||
|
@ -133,16 +131,10 @@ public:
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
|
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
showErrorInfo(oss, ei, showTrace);
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||||
|
|
||||||
log(*state, ei.level, oss.str());
|
log(*state, ei.level, oss.str());
|
||||||
}
|
}
|
||||||
bool getShowTrace() const override {
|
|
||||||
return showTrace;
|
|
||||||
}
|
|
||||||
void setShowTrace(bool showTrace) override {
|
|
||||||
this->showTrace = showTrace;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log(State & state, Verbosity lvl, const std::string & s)
|
void log(State & state, Verbosity lvl, const std::string & s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -323,9 +323,8 @@ int handleExceptions(const string & programName, std::function<void()> fun)
|
||||||
printError("Try '%1% --help' for more information.", programName);
|
printError("Try '%1% --help' for more information.", programName);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (BaseError & e) {
|
} catch (BaseError & e) {
|
||||||
logger->setShowTrace(settings.showTrace);
|
|
||||||
logError(e.info());
|
logError(e.info());
|
||||||
if (e.hasTrace() && !settings.showTrace)
|
if (e.hasTrace() && !loggerSettings.showTrace.get())
|
||||||
printError("(use '--show-trace' to show detailed location information)");
|
printError("(use '--show-trace' to show detailed location information)");
|
||||||
return e.status;
|
return e.status;
|
||||||
} catch (std::bad_alloc & e) {
|
} catch (std::bad_alloc & e) {
|
||||||
|
|
|
@ -41,10 +41,9 @@ struct TunnelLogger : public Logger
|
||||||
Sync<State> state_;
|
Sync<State> state_;
|
||||||
|
|
||||||
unsigned int clientVersion;
|
unsigned int clientVersion;
|
||||||
bool showTrace;
|
|
||||||
|
|
||||||
TunnelLogger(FdSink & to, unsigned int clientVersion)
|
TunnelLogger(FdSink & to, unsigned int clientVersion)
|
||||||
: to(to), clientVersion(clientVersion), showTrace(false) { }
|
: to(to), clientVersion(clientVersion) { }
|
||||||
|
|
||||||
void enqueueMsg(const std::string & s)
|
void enqueueMsg(const std::string & s)
|
||||||
{
|
{
|
||||||
|
@ -86,13 +85,6 @@ struct TunnelLogger : public Logger
|
||||||
enqueueMsg(*buf.s);
|
enqueueMsg(*buf.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getShowTrace() const override {
|
|
||||||
return showTrace;
|
|
||||||
}
|
|
||||||
void setShowTrace(bool showTrace) override {
|
|
||||||
this->showTrace = showTrace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* startWork() means that we're starting an operation for which we
|
/* startWork() means that we're starting an operation for which we
|
||||||
want to send out stderr to the client. */
|
want to send out stderr to the client. */
|
||||||
void startWork()
|
void startWork()
|
||||||
|
|
|
@ -196,10 +196,6 @@ public:
|
||||||
/* Whether to lock the Nix client and worker to the same CPU. */
|
/* Whether to lock the Nix client and worker to the same CPU. */
|
||||||
bool lockCPU;
|
bool lockCPU;
|
||||||
|
|
||||||
/* Whether to show a stack trace if Nix evaluation fails. */
|
|
||||||
Setting<bool> showTrace{this, false, "show-trace",
|
|
||||||
"Whether to show a stack trace on evaluation errors."};
|
|
||||||
|
|
||||||
Setting<SandboxMode> sandboxMode{this,
|
Setting<SandboxMode> sandboxMode{this,
|
||||||
#if __linux__
|
#if __linux__
|
||||||
smEnabled
|
smEnabled
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "pool.hh"
|
#include "pool.hh"
|
||||||
#include "finally.hh"
|
#include "finally.hh"
|
||||||
|
#include "logging.hh"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -197,7 +198,7 @@ void RemoteStore::setOptions(Connection & conn)
|
||||||
overrides.erase(settings.maxSilentTime.name);
|
overrides.erase(settings.maxSilentTime.name);
|
||||||
overrides.erase(settings.buildCores.name);
|
overrides.erase(settings.buildCores.name);
|
||||||
overrides.erase(settings.useSubstitutes.name);
|
overrides.erase(settings.useSubstitutes.name);
|
||||||
overrides.erase(settings.showTrace.name);
|
overrides.erase(loggerSettings.showTrace.name);
|
||||||
conn.to << overrides.size();
|
conn.to << overrides.size();
|
||||||
for (auto & i : overrides)
|
for (auto & i : overrides)
|
||||||
conn.to << i.first << i.second.value;
|
conn.to << i.first << i.second.value;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "logging.hh"
|
#include "logging.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
#include "config.hh"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
@ -7,6 +8,10 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
LoggerSettings loggerSettings;
|
||||||
|
|
||||||
|
static GlobalConfig::Register r1(&loggerSettings);
|
||||||
|
|
||||||
static thread_local ActivityId curActivity = 0;
|
static thread_local ActivityId curActivity = 0;
|
||||||
|
|
||||||
ActivityId getCurActivity()
|
ActivityId getCurActivity()
|
||||||
|
@ -18,7 +23,7 @@ void setCurActivity(const ActivityId activityId)
|
||||||
curActivity = activityId;
|
curActivity = activityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger * logger = makeSimpleLogger(true, false);
|
Logger * logger = makeSimpleLogger(true);
|
||||||
|
|
||||||
void Logger::warn(const std::string & msg)
|
void Logger::warn(const std::string & msg)
|
||||||
{
|
{
|
||||||
|
@ -36,10 +41,9 @@ public:
|
||||||
|
|
||||||
bool systemd, tty;
|
bool systemd, tty;
|
||||||
bool printBuildLogs;
|
bool printBuildLogs;
|
||||||
bool showTrace;
|
|
||||||
|
|
||||||
SimpleLogger(bool printBuildLogs, bool showTrace)
|
SimpleLogger(bool printBuildLogs)
|
||||||
: printBuildLogs(printBuildLogs), showTrace(showTrace)
|
: printBuildLogs(printBuildLogs)
|
||||||
{
|
{
|
||||||
systemd = getEnv("IN_SYSTEMD") == "1";
|
systemd = getEnv("IN_SYSTEMD") == "1";
|
||||||
tty = isatty(STDERR_FILENO);
|
tty = isatty(STDERR_FILENO);
|
||||||
|
@ -49,13 +53,6 @@ public:
|
||||||
return printBuildLogs;
|
return printBuildLogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getShowTrace() const override {
|
|
||||||
return showTrace;
|
|
||||||
}
|
|
||||||
void setShowTrace(bool showTrace) override {
|
|
||||||
this->showTrace = showTrace;
|
|
||||||
}
|
|
||||||
|
|
||||||
void log(Verbosity lvl, const FormatOrString & fs) override
|
void log(Verbosity lvl, const FormatOrString & fs) override
|
||||||
{
|
{
|
||||||
if (lvl > verbosity) return;
|
if (lvl > verbosity) return;
|
||||||
|
@ -80,7 +77,7 @@ public:
|
||||||
void logEI(const ErrorInfo & ei) override
|
void logEI(const ErrorInfo & ei) override
|
||||||
{
|
{
|
||||||
std::stringstream oss;
|
std::stringstream oss;
|
||||||
showErrorInfo(oss, ei, showTrace);
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||||
|
|
||||||
log(ei.level, oss.str());
|
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};
|
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
|
||||||
|
@ -152,13 +149,6 @@ struct JSONLogger : Logger {
|
||||||
return true;
|
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)
|
void addFields(nlohmann::json & json, const Fields & fields)
|
||||||
{
|
{
|
||||||
if (fields.empty()) return;
|
if (fields.empty()) return;
|
||||||
|
@ -189,7 +179,7 @@ struct JSONLogger : Logger {
|
||||||
void logEI(const ErrorInfo & ei) override
|
void logEI(const ErrorInfo & ei) override
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
showErrorInfo(oss, ei, getShowTrace());
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||||
|
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
json["action"] = "msg";
|
json["action"] = "msg";
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include "error.hh"
|
#include "error.hh"
|
||||||
|
#include "config.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -34,6 +35,16 @@ typedef enum {
|
||||||
|
|
||||||
typedef uint64_t ActivityId;
|
typedef uint64_t ActivityId;
|
||||||
|
|
||||||
|
struct LoggerSettings : Config
|
||||||
|
{
|
||||||
|
Setting<bool> showTrace{this,
|
||||||
|
false,
|
||||||
|
"show-trace",
|
||||||
|
"Whether to show a stack trace on evaluation errors."};
|
||||||
|
};
|
||||||
|
|
||||||
|
extern LoggerSettings loggerSettings;
|
||||||
|
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
friend struct Activity;
|
friend struct Activity;
|
||||||
|
@ -75,9 +86,6 @@ public:
|
||||||
logEI(ei);
|
logEI(ei);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool getShowTrace() const = 0;
|
|
||||||
virtual void setShowTrace(bool showTrace) = 0;
|
|
||||||
|
|
||||||
virtual void warn(const std::string & msg);
|
virtual void warn(const std::string & msg);
|
||||||
|
|
||||||
virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||||
|
@ -149,7 +157,7 @@ struct PushActivity
|
||||||
|
|
||||||
extern Logger * logger;
|
extern Logger * logger;
|
||||||
|
|
||||||
Logger * makeSimpleLogger(bool printBuildLogs = true, bool showTrace = false);
|
Logger * makeSimpleLogger(bool printBuildLogs = true);
|
||||||
|
|
||||||
Logger * makeJSONLogger(Logger & prevLogger);
|
Logger * makeJSONLogger(Logger & prevLogger);
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,7 @@ namespace nix {
|
||||||
|
|
||||||
testing::internal::CaptureStderr();
|
testing::internal::CaptureStderr();
|
||||||
|
|
||||||
logger->setShowTrace(true);
|
loggerSettings.showTrace.assign(true);
|
||||||
|
|
||||||
logError(e.info());
|
logError(e.info());
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ namespace nix {
|
||||||
|
|
||||||
testing::internal::CaptureStderr();
|
testing::internal::CaptureStderr();
|
||||||
|
|
||||||
logger->setShowTrace(false);
|
loggerSettings.showTrace.assign(false);
|
||||||
|
|
||||||
logError(e.info());
|
logError(e.info());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue