mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 21:16:02 +01:00
showTrace flag in loggers
This commit is contained in:
parent
ef24a0835d
commit
8f81fae116
10 changed files with 60 additions and 20 deletions
|
|
@ -22,11 +22,11 @@ LogFormat parseLogFormat(const std::string & logFormatStr) {
|
|||
Logger * makeDefaultLogger() {
|
||||
switch (defaultLogFormat) {
|
||||
case LogFormat::raw:
|
||||
return makeSimpleLogger(false);
|
||||
return makeSimpleLogger(false, false);
|
||||
case LogFormat::rawWithLogs:
|
||||
return makeSimpleLogger(true);
|
||||
return makeSimpleLogger(true, false);
|
||||
case LogFormat::internalJson:
|
||||
return makeJSONLogger(*makeSimpleLogger());
|
||||
return makeJSONLogger(*makeSimpleLogger(true, false));
|
||||
case LogFormat::bar:
|
||||
return makeProgressBar();
|
||||
case LogFormat::barWithLogs:
|
||||
|
|
|
|||
|
|
@ -81,12 +81,14 @@ private:
|
|||
|
||||
bool printBuildLogs;
|
||||
bool isTTY;
|
||||
bool showTrace;
|
||||
|
||||
public:
|
||||
|
||||
ProgressBar(bool printBuildLogs, bool isTTY)
|
||||
: printBuildLogs(printBuildLogs)
|
||||
, isTTY(isTTY)
|
||||
, showTrace(false)
|
||||
{
|
||||
state_.lock()->active = isTTY;
|
||||
updateThread = std::thread([&]() {
|
||||
|
|
@ -131,10 +133,17 @@ public:
|
|||
auto state(state_.lock());
|
||||
|
||||
std::stringstream oss;
|
||||
oss << ei;
|
||||
showErrorInfo(oss, ei, showTrace);
|
||||
// oss << ei;
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -303,7 +303,6 @@ int handleExceptions(const string & programName, std::function<void()> fun)
|
|||
ReceiveInterrupts receiveInterrupts; // FIXME: need better place for this
|
||||
|
||||
ErrorInfo::programName = baseNameOf(programName);
|
||||
ErrorInfo::showTrace = settings.showTrace;
|
||||
|
||||
string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
||||
try {
|
||||
|
|
@ -324,6 +323,7 @@ int handleExceptions(const string & programName, std::function<void()> fun)
|
|||
printError("Try '%1% --help' for more information.", programName);
|
||||
return 1;
|
||||
} catch (BaseError & e) {
|
||||
logger->setShowTrace(settings.showTrace);
|
||||
logError(e.info());
|
||||
// TODO fix to detect non-empty trace here.
|
||||
if (e.hasTrace() && !settings.showTrace)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue