зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1165515 - Part 13-1: Add log level enum class. r=froydnj
This adds the mozilla::LogLevel enum class. Additionaly a log_test function is added to use rather than a macro, this allows us to enforce only mozilla::LogLevel is passed into the function.
This commit is contained in:
Родитель
c3237a9993
Коммит
7fe9ffc48b
|
@ -9,20 +9,59 @@
|
|||
|
||||
#include "prlog.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
// This file is a placeholder for a replacement to the NSPR logging framework
|
||||
// that is defined in prlog.h. Currently it is just a pass through, but as
|
||||
// work progresses more functionality will be swapped out in favor of
|
||||
// mozilla logging implementations.
|
||||
|
||||
#define PR_LOG_INFO PR_LOG_DEBUG
|
||||
#define PR_LOG_VERBOSE (PR_LOG_DEBUG + 1)
|
||||
namespace mozilla {
|
||||
|
||||
#define MOZ_LOG PR_LOG
|
||||
// While not a 100% mapping to PR_LOG's numeric values, mozilla::LogLevel does
|
||||
// maintain a direct mapping for the Disabled, Debug and Verbose levels.
|
||||
//
|
||||
// Mappings of LogLevel to PR_LOG's numeric values:
|
||||
//
|
||||
// +---------+------------------+-----------------+
|
||||
// | Numeric | NSPR Logging | Mozilla Logging |
|
||||
// +---------+------------------+-----------------+
|
||||
// | 0 | PR_LOG_NONE | Disabled |
|
||||
// | 1 | PR_LOG_ALWAYS | Error |
|
||||
// | 2 | PR_LOG_ERROR | Warning |
|
||||
// | 3 | PR_LOG_WARNING | Info |
|
||||
// | 4 | PR_LOG_DEBUG | Debug |
|
||||
// | 5 | PR_LOG_DEBUG + 1 | Verbose |
|
||||
// +---------+------------------+-----------------+
|
||||
//
|
||||
enum class LogLevel {
|
||||
Disabled = 0,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Debug,
|
||||
Verbose,
|
||||
};
|
||||
|
||||
// Tests if a module has enabled the given log level.
|
||||
// NB: _module can be null.
|
||||
#define MOZ_LOG_TEST(_module, _level) \
|
||||
((_module) && (_module)->level >= (_level))
|
||||
namespace detail {
|
||||
|
||||
inline bool log_test(const PRLogModuleInfo* module, LogLevel level) {
|
||||
MOZ_ASSERT(level != LogLevel::Disabled);
|
||||
return module && module->level >= static_cast<int>(level);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define MOZ_LOG_TEST(_module,_level) mozilla::detail::log_test(_module, _level)
|
||||
|
||||
#define MOZ_LOG(_module,_level,_args) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (MOZ_LOG_TEST(_module,_level)) { \
|
||||
PR_LogPrint _args; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#endif // mozilla_logging_h
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче