--- a/dom/media/doctor/DDLogCategory.cpp
+++ b/dom/media/doctor/DDLogCategory.cpp
@@ -4,19 +4,29 @@
* 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 "DDLogCategory.h"
namespace mozilla {
const char* const kDDLogCategoryShortStrings[kDDLogCategoryCount] = {
- "con", "dcn", "des", "lnk", "ulk", "prp", "evt", "api", "log"
+ "con", "dcn", "des", "lnk", "ulk", "prp", "evt",
+ "api", "log", "mze", "mzw", "mzi", "mzd", "mzv"
};
const char* const kDDLogCategoryLongStrings[kDDLogCategoryCount] = {
- "Construction", "Derived Construction",
- "Destruction", "Link",
- "Unlink", "Property",
- "Event", "API",
- "Log"
+ "Construction",
+ "Derived Construction",
+ "Destruction",
+ "Link",
+ "Unlink",
+ "Property",
+ "Event",
+ "API",
+ "Log",
+ "MozLog-Error",
+ "MozLog-Warning",
+ "MozLog-Info",
+ "MozLog-Debug",
+ "MozLog-Verbose"
};
} // namespace mozilla
--- a/dom/media/doctor/DecoderDoctorLogger.h
+++ b/dom/media/doctor/DecoderDoctorLogger.h
@@ -122,47 +122,136 @@ public:
DDLogCategory aCategory,
const char* aLabel,
const char* aValue)
{
EagerLogValue(
DDLoggedTypeTraits<Subject>::Name(), aSubject, aCategory, aLabel, aValue);
}
+ static void EagerLogPrintf(const char* aSubjectTypeName,
+ const void* aSubjectPointer,
+ DDLogCategory aCategory,
+ const char* aLabel,
+ const char* aString)
+ {
+ Log(aSubjectTypeName,
+ aSubjectPointer,
+ aCategory,
+ aLabel,
+ DDLogValue{ nsCString{ aString } });
+ }
+
template<typename... Args>
static void EagerLogPrintf(const char* aSubjectTypeName,
const void* aSubjectPointer,
DDLogCategory aCategory,
const char* aLabel,
const char* aFormat,
Args&&... aArgs)
{
Log(aSubjectTypeName,
aSubjectPointer,
aCategory,
aLabel,
DDLogValue{
nsCString{ nsPrintfCString(aFormat, Forward<Args>(aArgs)...) } });
}
+ template<typename Subject>
+ static void EagerLogPrintf(const Subject* aSubject,
+ DDLogCategory aCategory,
+ const char* aLabel,
+ const char* aString)
+ {
+ EagerLogPrintf(DDLoggedTypeTraits<Subject>::Name(),
+ aSubject,
+ aCategory,
+ aLabel,
+ aString);
+ }
+
template<typename Subject, typename... Args>
static void EagerLogPrintf(const Subject* aSubject,
DDLogCategory aCategory,
const char* aLabel,
const char* aFormat,
Args&&... aArgs)
{
EagerLogPrintf(DDLoggedTypeTraits<Subject>::Name(),
aSubject,
aCategory,
aLabel,
aFormat,
Forward<Args>(aArgs)...);
}
+ static void MozLogPrintf(const char* aSubjectTypeName,
+ const void* aSubjectPointer,
+ const LogModule* aLogModule,
+ LogLevel aLogLevel,
+ const char* aString)
+ {
+ Log(aSubjectTypeName,
+ aSubjectPointer,
+ CategoryForMozLogLevel(aLogLevel),
+ aLogModule->Name(), // LogModule name as label.
+ DDLogValue{ nsCString{ aString } });
+ MOZ_LOG(aLogModule,
+ aLogLevel,
+ ("%s[%p] %s", aSubjectTypeName, aSubjectPointer, aString));
+ }
+
+ template<typename... Args>
+ static void MozLogPrintf(const char* aSubjectTypeName,
+ const void* aSubjectPointer,
+ const LogModule* aLogModule,
+ LogLevel aLogLevel,
+ const char* aFormat,
+ Args&&... aArgs)
+ {
+ nsCString printed = nsPrintfCString(aFormat, Forward<Args>(aArgs)...);
+ Log(aSubjectTypeName,
+ aSubjectPointer,
+ CategoryForMozLogLevel(aLogLevel),
+ aLogModule->Name(), // LogModule name as label.
+ DDLogValue{ printed });
+ MOZ_LOG(aLogModule,
+ aLogLevel,
+ ("%s[%p] %s", aSubjectTypeName, aSubjectPointer, printed.get()));
+ }
+
+ template<typename Subject>
+ static void MozLogPrintf(const Subject* aSubject,
+ const LogModule* aLogModule,
+ LogLevel aLogLevel,
+ const char* aString)
+ {
+ MozLogPrintf(DDLoggedTypeTraits<Subject>::Name(),
+ aSubject,
+ aLogModule,
+ aLogLevel,
+ aString);
+ }
+
+ template<typename Subject, typename... Args>
+ static void MozLogPrintf(const Subject* aSubject,
+ const LogModule* aLogModule,
+ LogLevel aLogLevel,
+ const char* aFormat,
+ Args&&... aArgs)
+ {
+ MozLogPrintf(DDLoggedTypeTraits<Subject>::Name(),
+ aSubject,
+ aLogModule,
+ aLogLevel,
+ aFormat,
+ Forward<Args>(aArgs)...);
+ }
+
// Special logging functions. Consider using DecoderDoctorLifeLogger to
// automatically capture constructions & destructions.
static void LogConstruction(const char* aSubjectTypeName,
const void* aSubjectPointer)
{
Log(aSubjectTypeName,
aSubjectPointer,
@@ -334,16 +423,39 @@ private:
static void PanicInternal(const char* aReason, bool aDontBlock);
static void Log(const char* aSubjectTypeName,
const void* aSubjectPointer,
DDLogCategory aCategory,
const char* aLabel,
DDLogValue&& aValue);
+ static void Log(const char* aSubjectTypeName,
+ const void* aSubjectPointer,
+ const LogModule* aLogModule,
+ LogLevel aLogLevel,
+ DDLogValue&& aValue);
+
+ static DDLogCategory CategoryForMozLogLevel(LogLevel aLevel)
+ {
+ switch (aLevel) {
+ default:
+ case LogLevel::Error:
+ return DDLogCategory::MozLogError;
+ case LogLevel::Warning:
+ return DDLogCategory::MozLogWarning;
+ case LogLevel::Info:
+ return DDLogCategory::MozLogInfo;
+ case LogLevel::Debug:
+ return DDLogCategory::MozLogDebug;
+ case LogLevel::Verbose:
+ return DDLogCategory::MozLogVerbose;
+ }
+ }
+
using LogState = int;
// Currently disabled, may be enabled on request.
static constexpr LogState scDisabled = 0;
// Currently enabled (logging happens), may be shutdown.
static constexpr LogState scEnabled = 1;
// Still disabled, but one thread is working on enabling it, nobody else
// should interfere during this time.
static constexpr LogState scEnabling = 2;
@@ -401,28 +513,28 @@ public:
_typename, _this, _category, _label, _arg); \
} \
} while (0)
#ifdef DEBUG
// Do a printf format check in DEBUG, with the downside that side-effects (from
// evaluating the arguments) may happen twice! Who would do that anyway?
static void inline MOZ_FORMAT_PRINTF(1, 2) DDLOGPRCheck(const char*, ...) {}
-#define DDLOGPR_CHECK(_fmt, ...) DDLOGPRCheck(_fmt, __VA_ARGS__)
+#define DDLOGPR_CHECK(_fmt, ...) DDLOGPRCheck(_fmt, ##__VA_ARGS__)
#else
#define DDLOGPR_CHECK(_fmt, ...)
#endif
// Log a printf'd string. Discouraged, please try using DDLOG instead.
#define DDLOGPR(_category, _label, _format, ...) \
do { \
if (DecoderDoctorLogger::IsDDLoggingEnabled()) { \
- DDLOGPR_CHECK(_format, __VA_ARGS__); \
+ DDLOGPR_CHECK(_format, ##__VA_ARGS__); \
DecoderDoctorLogger::EagerLogPrintf( \
- this, _category, _label, _format, __VA_ARGS__); \
+ this, _category, _label, _format, ##__VA_ARGS__); \
} \
} while (0)
// Link a child object.
#define DDLINKCHILD(...) \
do { \
if (DecoderDoctorLogger::IsDDLoggingEnabled()) { \
DecoderDoctorLogger::LinkParentAndChild(this, __VA_ARGS__); \
@@ -432,11 +544,38 @@ static void inline MOZ_FORMAT_PRINTF(1,
// Unlink a child object.
#define DDUNLINKCHILD(...) \
do { \
if (DecoderDoctorLogger::IsDDLoggingEnabled()) { \
DecoderDoctorLogger::UnlinkParentAndChild(this, __VA_ARGS__); \
} \
} while (0)
+// Log a printf'd string to DDLogger and/or MOZ_LOG, with an EXplicit `this`.
+// Don't even call MOZ_LOG on Android non-release/beta; See Logging.h.
+#if !defined(ANDROID) || !defined(RELEASE_OR_BETA)
+#define DDMOZ_LOGEX(_this, _logModule, _logLevel, _format, ...) \
+ do { \
+ if (DecoderDoctorLogger::IsDDLoggingEnabled() || \
+ MOZ_LOG_TEST(_logModule, _logLevel)) { \
+ DDLOGPR_CHECK(_format, ##__VA_ARGS__); \
+ DecoderDoctorLogger::MozLogPrintf( \
+ _this, _logModule, _logLevel, _format, ##__VA_ARGS__); \
+ } \
+ } while (0)
+#else
+#define DDMOZ_LOGEX(_this, _logModule, _logLevel, _format, ...) \
+ do { \
+ if (DecoderDoctorLogger::IsDDLoggingEnabled()) { \
+ DDLOGPR_CHECK(_format, ##__VA_ARGS__); \
+ DecoderDoctorLogger::MozLogPrintf( \
+ _this, _logModule, _logLevel, _format, ##__VA_ARGS__); \
+ } \
+ } while (0)
+#endif
+
+// Log a printf'd string to DDLogger and/or MOZ_LOG.
+#define DDMOZ_LOG(_logModule, _logLevel, _format, ...) \
+ DDMOZ_LOGEX(this, _logModule, _logLevel, _format, ##__VA_ARGS__)
+
} // namespace mozilla
#endif // DecoderDoctorLogger_h_