diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 725f71be072..22ac50102de 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -827,6 +827,8 @@ public: uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0); + static void LogMessageToConsole(const char* aMsg, ...); + /** * Get the localized string named |aKey| in properties file |aFile|. */ diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index e0e4b76e4bd..f8fa479b2e8 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -11,6 +11,7 @@ #include #include +#include "prprf.h" #include "nsCxPusher.h" #include "DecoderTraits.h" #include "harfbuzz/hb.h" @@ -3149,6 +3150,28 @@ nsContentUtils::ReportToConsoleNonLocalized(const nsAString& aErrorText, return sConsoleService->LogMessage(errorObject); } +void +nsContentUtils::LogMessageToConsole(const char* aMsg, ...) +{ + if (!sConsoleService) { // only need to bother null-checking here + CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService); + if (!sConsoleService) { + return; + } + } + + va_list args; + va_start(args, aMsg); + char* formatted = PR_vsmprintf(aMsg, args); + va_end(args); + if (!formatted) { + return; + } + + sConsoleService->LogStringMessage(NS_ConvertUTF8toUTF16(formatted).get()); + PR_smprintf_free(formatted); +} + bool nsContentUtils::IsChromeDoc(nsIDocument *aDocument) {