Add warn function

This commit is contained in:
Eelco Dolstra 2017-04-12 14:53:10 +02:00
parent 31cc9366fc
commit 6d97d81656
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 16 additions and 1 deletions

View file

@ -5,6 +5,11 @@ namespace nix {
Logger * logger = makeDefaultLogger(); Logger * logger = makeDefaultLogger();
void Logger::warn(const std::string & msg)
{
log(lvlInfo, ANSI_RED "warning:" ANSI_NORMAL " " + msg);
}
class SimpleLogger : public Logger class SimpleLogger : public Logger
{ {
public: public:
@ -52,7 +57,7 @@ Verbosity verbosity = lvlInfo;
void warnOnce(bool & haveWarned, const FormatOrString & fs) void warnOnce(bool & haveWarned, const FormatOrString & fs)
{ {
if (!haveWarned) { if (!haveWarned) {
printError(format("warning: %1%") % fs.s); warn(fs.s);
haveWarned = true; haveWarned = true;
} }
} }

View file

@ -30,6 +30,8 @@ public:
log(lvlInfo, fs); log(lvlInfo, fs);
} }
virtual void warn(const std::string & msg);
virtual void setExpected(const std::string & label, uint64_t value = 1) { } virtual void setExpected(const std::string & label, uint64_t value = 1) { }
virtual void setProgress(const std::string & label, uint64_t value = 1) { } virtual void setProgress(const std::string & label, uint64_t value = 1) { }
virtual void incExpected(const std::string & label, uint64_t value = 1) { } virtual void incExpected(const std::string & label, uint64_t value = 1) { }
@ -82,6 +84,14 @@ extern Verbosity verbosity; /* suppress msgs > this */
#define debug(args...) printMsg(lvlDebug, args) #define debug(args...) printMsg(lvlDebug, args)
#define vomit(args...) printMsg(lvlVomit, args) #define vomit(args...) printMsg(lvlVomit, args)
template<typename... Args>
inline void warn(const std::string & fs, Args... args)
{
boost::format f(fs);
formatHelper(f, args...);
logger->warn(f.str());
}
void warnOnce(bool & haveWarned, const FormatOrString & fs); void warnOnce(bool & haveWarned, const FormatOrString & fs);
void writeToStderr(const string & s); void writeToStderr(const string & s);