mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1158430 - A small construct to allow only sending errors and warnings once per statement. r=botond
This commit is contained in:
parent
0bb27285c5
commit
ef1c3c797b
@ -220,6 +220,9 @@ public:
|
||||
NoLog() {}
|
||||
~NoLog() {}
|
||||
|
||||
// No-op
|
||||
MOZ_IMPLICIT NoLog(const NoLog&) {}
|
||||
|
||||
template<typename T>
|
||||
NoLog &operator <<(const T &aLogText) { return *this; }
|
||||
};
|
||||
@ -253,18 +256,10 @@ public:
|
||||
// Logger::ShouldOutputMessage. Since we currently don't have a different
|
||||
// version of that method for different loggers, this is OK. Once we do,
|
||||
// change BasicLogger::ShouldOutputMessage to Logger::ShouldOutputMessage.
|
||||
explicit Log(int aOptions = Log::DefaultOptions(L == LOG_CRITICAL))
|
||||
: mOptions(aOptions)
|
||||
, mLogIt(BasicLogger::ShouldOutputMessage(L))
|
||||
{
|
||||
if (mLogIt && AutoPrefix()) {
|
||||
if (mOptions & int(LogOptions::AssertOnCall)) {
|
||||
mMessage << "[GFX" << L << "]: ";
|
||||
} else {
|
||||
mMessage << "[GFX" << L << "-]: ";
|
||||
}
|
||||
}
|
||||
explicit Log(int aOptions = Log::DefaultOptions(L == LOG_CRITICAL)) {
|
||||
Init(aOptions, BasicLogger::ShouldOutputMessage(L));
|
||||
}
|
||||
|
||||
~Log() {
|
||||
Flush();
|
||||
}
|
||||
@ -276,12 +271,6 @@ public:
|
||||
if (!str.empty()) {
|
||||
WriteLog(str);
|
||||
}
|
||||
if (AutoPrefix()) {
|
||||
mMessage.str("[GFX");
|
||||
mMessage << L << "]: ";
|
||||
} else {
|
||||
mMessage.str("");
|
||||
}
|
||||
mMessage.clear();
|
||||
}
|
||||
|
||||
@ -478,8 +467,24 @@ public:
|
||||
inline bool NoNewline() const { return mOptions & int(LogOptions::NoNewline); }
|
||||
inline bool AutoPrefix() const { return mOptions & int(LogOptions::AutoPrefix); }
|
||||
|
||||
// We do not want this version to do any work, and stringstream can't be
|
||||
// copied anyway. It does come in handy for the "Once" macro defined below.
|
||||
MOZ_IMPLICIT Log(const Log& log) { Init(log.mOptions, false); }
|
||||
|
||||
private:
|
||||
// Initialization common to two constructors
|
||||
void Init(int aOptions, bool aLogIt) {
|
||||
mOptions = aOptions;
|
||||
mLogIt = aLogIt;
|
||||
if (mLogIt && AutoPrefix()) {
|
||||
if (mOptions & int(LogOptions::AssertOnCall)) {
|
||||
mMessage << "[GFX" << L << "]: ";
|
||||
} else {
|
||||
mMessage << "[GFX" << L << "-]: ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WriteLog(const std::string &aString) {
|
||||
if (MOZ_UNLIKELY(LogIt())) {
|
||||
Logger::OutputMessage(aString, L, NoNewline());
|
||||
@ -498,19 +503,39 @@ typedef Log<LOG_DEBUG> DebugLog;
|
||||
typedef Log<LOG_WARNING> WarningLog;
|
||||
typedef Log<LOG_CRITICAL, CriticalLogger> CriticalLog;
|
||||
|
||||
#ifdef GFX_LOG_DEBUG
|
||||
#define gfxDebug mozilla::gfx::DebugLog
|
||||
#else
|
||||
#define gfxDebug if (1) ; else mozilla::gfx::NoLog
|
||||
#endif
|
||||
#ifdef GFX_LOG_WARNING
|
||||
#define gfxWarning mozilla::gfx::WarningLog
|
||||
#else
|
||||
#define gfxWarning if (1) ; else mozilla::gfx::NoLog
|
||||
// Macro to glue names to get us less chance of name clashing.
|
||||
#if defined GFX_LOGGING_GLUE1 || defined GFX_LOGGING_GLUE
|
||||
#error "Clash of the macro GFX_LOGGING_GLUE1 or GFX_LOGGING_GLUE"
|
||||
#endif
|
||||
#define GFX_LOGGING_GLUE1(x, y) x##y
|
||||
#define GFX_LOGGING_GLUE(x, y) GFX_LOGGING_GLUE1(x, y)
|
||||
|
||||
// This log goes into crash reports, use with care.
|
||||
#define gfxCriticalError mozilla::gfx::CriticalLog
|
||||
#define gfxCriticalErrorOnce static gfxCriticalError GFX_LOGGING_GLUE(sOnceAtLine,__LINE__) = gfxCriticalError
|
||||
|
||||
// The "once" versions will only trigger the first time through. You can do this:
|
||||
// gfxCriticalErrorOnce() << "This message only shows up once;
|
||||
// instead of the usual:
|
||||
// static bool firstTime = true;
|
||||
// if (firstTime) {
|
||||
// firstTime = false;
|
||||
// gfxCriticalError() << "This message only shows up once;
|
||||
// }
|
||||
#ifdef GFX_LOG_DEBUG
|
||||
#define gfxDebug mozilla::gfx::DebugLog
|
||||
#define gfxDebugOnce static gfxDebug GFX_LOGGING_GLUE(sOnceAtLine,__LINE__) = gfxDebug
|
||||
#else
|
||||
#define gfxDebug if (1) ; else mozilla::gfx::NoLog
|
||||
#define gfxDebugOnce if (1) ; else mozilla::gfx::NoLog
|
||||
#endif
|
||||
#ifdef GFX_LOG_WARNING
|
||||
#define gfxWarning mozilla::gfx::WarningLog
|
||||
#define gfxWarningOnce static gfxWarning GFX_LOGGING_GLUE(sOnceAtLine,__LINE__) = gfxWarning
|
||||
#else
|
||||
#define gfxWarning if (1) ; else mozilla::gfx::NoLog
|
||||
#define gfxWarningOnce if (1) ; else mozilla::gfx::NoLog
|
||||
#endif
|
||||
|
||||
// See nsDebug.h and the NS_WARN_IF macro
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user