зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1904429 - Extract some core logging types into their own header file r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D217873
This commit is contained in:
Родитель
a85b25946f
Коммит
6e50ad8063
|
@ -0,0 +1,18 @@
|
|||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "LoggingCore.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
LogLevel ToLogLevel(int32_t aLevel) {
|
||||
aLevel = std::min(aLevel, static_cast<int32_t>(LogLevel::Verbose));
|
||||
aLevel = std::max(aLevel, static_cast<int32_t>(LogLevel::Disabled));
|
||||
return static_cast<LogLevel>(aLevel);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,49 @@
|
|||
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Shared logging infrastructure across different binaries.
|
||||
|
||||
#ifndef _mozilla_LoggingCore_h
|
||||
#define _mozilla_LoggingCore_h
|
||||
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Types.h"
|
||||
|
||||
namespace mozilla {
|
||||
// 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,
|
||||
};
|
||||
|
||||
/**
|
||||
* Safely converts an integer into a valid LogLevel.
|
||||
*/
|
||||
MFBT_API LogLevel ToLogLevel(int32_t aLevel);
|
||||
|
||||
using AtomicLogLevel = Atomic<LogLevel, Relaxed>;
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* _mozilla_LoggingCore_h */
|
|
@ -12,6 +12,7 @@ EXPORTS.mozilla += [
|
|||
"decimal/Decimal.h",
|
||||
"decimal/DoubleConversion.h",
|
||||
"IntegerPrintfMacros.h",
|
||||
"LoggingCore.h",
|
||||
"MmapFaultHandler.h",
|
||||
"PlatformConditionVariable.h",
|
||||
"PlatformMutex.h",
|
||||
|
@ -44,6 +45,7 @@ SOURCES += [
|
|||
"AutoProfilerLabel.cpp",
|
||||
"AwakeTimeStamp.cpp",
|
||||
"Debug.cpp",
|
||||
"LoggingCore.cpp",
|
||||
"MmapFaultHandler.cpp",
|
||||
"Printf.cpp",
|
||||
"SIMD.cpp",
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
#include "mozilla/Logging.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/process_util.h"
|
||||
#include "GeckoProfiler.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
|
@ -73,12 +71,6 @@ void log_print(const LogModule* aModule, LogLevel aLevel, TimeStamp* aStart,
|
|||
|
||||
} // namespace detail
|
||||
|
||||
LogLevel ToLogLevel(int32_t aLevel) {
|
||||
aLevel = std::min(aLevel, static_cast<int32_t>(LogLevel::Verbose));
|
||||
aLevel = std::max(aLevel, static_cast<int32_t>(LogLevel::Disabled));
|
||||
return static_cast<LogLevel>(aLevel);
|
||||
}
|
||||
|
||||
static const char* ToLogStr(LogLevel aLevel) {
|
||||
switch (aLevel) {
|
||||
case LogLevel::Error:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/LoggingCore.h"
|
||||
|
||||
#define MOZ_LOGGING_ENABLED 1
|
||||
|
||||
|
@ -30,36 +31,6 @@ namespace mozilla {
|
|||
|
||||
class TimeStamp;
|
||||
|
||||
// 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,
|
||||
};
|
||||
|
||||
/**
|
||||
* Safely converts an integer into a valid LogLevel.
|
||||
*/
|
||||
LogLevel ToLogLevel(int32_t aLevel);
|
||||
|
||||
class LogModule {
|
||||
public:
|
||||
~LogModule() { ::free(mName); }
|
||||
|
@ -157,7 +128,7 @@ class LogModule {
|
|||
|
||||
char* mName;
|
||||
|
||||
Atomic<LogLevel, Relaxed> mLevel;
|
||||
AtomicLogLevel mLevel;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче