7#include <nlohmann/json_fwd.hpp>
14 actFileTransfer = 101,
19 actOptimiseStore = 106,
22 actQueryPathInfo = 109,
23 actPostBuildHook = 110,
24 actBuildWaiting = 111,
30 resBuildLogLine = 101,
31 resUntrustedPath = 102,
32 resCorruptedPath = 103,
36 resPostBuildLogLine = 107,
40typedef uint64_t ActivityId;
45 this,
false,
"show-trace",
47 Whether Nix should print out a stack trace in case of Nix
48 expression evaluation errors.
56 friend struct Activity;
63 enum { tInt = 0, tString = 1 } type;
66 Field(
const std::string & s) : type(tString), s(s) { }
67 Field(
const char * s) : type(tString), s(s) { }
68 Field(
const uint64_t & i) : type(tInt), i(i) { }
71 typedef std::vector<Field> Fields;
75 virtual void stop() { };
77 virtual void pause() { };
78 virtual void resume() { };
81 virtual bool isVerbose() {
return false; }
83 virtual void log(Verbosity lvl, std::string_view
s) = 0;
85 void log(std::string_view
s)
90 virtual void logEI(
const ErrorInfo & ei) = 0;
92 void logEI(Verbosity lvl, ErrorInfo ei)
98 virtual void warn(
const std::string & msg);
100 virtual void startActivity(ActivityId
act, Verbosity lvl, ActivityType
type,
101 const std::string &
s,
const Fields & fields, ActivityId
parent) { };
103 virtual void stopActivity(ActivityId
act) { };
105 virtual void result(ActivityId
act, ResultType
type,
const Fields & fields) { };
107 virtual void writeToStdout(std::string_view
s);
109 template<
typename... Args>
110 inline void cout(
const Args & ...
args)
115 virtual std::optional<char> ask(std::string_view
s)
118 virtual void setPrintBuildLogs(
bool printBuildLogs)
129 template<
typename... T> nop(T...)
133ActivityId getCurActivity();
134void setCurActivity(
const ActivityId activityId);
142 Activity(Logger & logger, Verbosity lvl, ActivityType
type,
const std::string &
s =
"",
143 const Logger::Fields & fields = {}, ActivityId
parent = getCurActivity());
145 Activity(Logger & logger, ActivityType
type,
146 const Logger::Fields & fields = {}, ActivityId
parent = getCurActivity())
147 : Activity(logger, lvlError,
type,
"", fields,
parent) { };
149 Activity(
const Activity &
act) =
delete;
153 void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0)
const
154 { result(resProgress, done, expected, running, failed); }
156 void setExpected(ActivityType type2, uint64_t expected)
const
157 { result(resSetExpected, type2, expected); }
159 template<
typename...
Args>
160 void result(ResultType
type,
const Args & ...
args)
const
162 Logger::Fields fields;
164 result(
type, fields);
167 void result(ResultType
type,
const Logger::Fields & fields)
const
169 logger.result(
id,
type, fields);
177 const ActivityId prevAct;
178 PushActivity(ActivityId
act) : prevAct(getCurActivity()) { setCurActivity(
act); }
179 ~PushActivity() { setCurActivity(prevAct); }
184Logger * makeSimpleLogger(
bool printBuildLogs =
true);
191std::optional<nlohmann::json> parseJSONMessage(
const std::string & msg, std::string_view source);
196bool handleJSONLogMessage(nlohmann::json & json,
197 const Activity &
act, std::map<ActivityId, Activity> & activities,
198 std::string_view source,
204bool handleJSONLogMessage(
const std::string & msg,
205 const Activity &
act, std::map<ActivityId, Activity> & activities,
206 std::string_view source,
212extern Verbosity verbosity;
220#define logErrorInfo(level, errorInfo...) \
222 if ((level) <= nix::verbosity) { \
223 logger->logEI((level), errorInfo); \
227#define logError(errorInfo...) logErrorInfo(lvlError, errorInfo)
228#define logWarning(errorInfo...) logErrorInfo(lvlWarn, errorInfo)
235#define printMsgUsing(loggerParam, level, args...) \
237 auto __lvl = level; \
238 if (__lvl <= nix::verbosity) { \
239 loggerParam->log(__lvl, fmt(args)); \
242#define printMsg(level, args...) printMsgUsing(logger, level, args)
244#define printError(args...) printMsg(lvlError, args)
245#define notice(args...) printMsg(lvlNotice, args)
246#define printInfo(args...) printMsg(lvlInfo, args)
247#define printTalkative(args...) printMsg(lvlTalkative, args)
248#define debug(args...) printMsg(lvlDebug, args)
249#define vomit(args...) printMsg(lvlVomit, args)
254template<
typename... Args>
259 logger->warn(
f.str());
262#define warnOnce(haveWarned, args...) \
268void writeToStderr(std::string_view
s);
This file defines two main structs/classes used in nix error handling.
void formatHelper(F &f)
Definition fmt.hh:24
std::string fmt(const std::string &s)
Definition fmt.hh:67
const Activity & act
Definition lexer.l:2371
std::optional< CanonPath > parent() const
return s
Definition lexer.l:459
ValueType type
Definition lexer.l:7098
std::vector< Expr * > args
Definition lexer.l:6126
void warn(const std::string &fs, const Args &... args)
Definition logging.hh:255
Definition logging.hh:137
Definition logging.hh:128