Skip to content

Commit

Permalink
Bug 1687553 - Make more dump implementations log to MOZ_LOG system …
Browse files Browse the repository at this point in the history
…under module "Dump". r=xpcom-reviewers,nika

This is an extension of the existing implementations added by Bug
1059469.

By extension, this makes `console.log` and friends log to the MOZ_LOG
system when `browser.dom.window.dump.enabled` is true.

My immediate use case is capturing cumulative logs for the new
`--backgroundtask ...` mode that will be used to invoke maintenance
tasks when Firefox itself is not running.

This will lead to duplicate messages (from both the MOZ_LOG system and
`fputs`) when the MOZ_LOG system is not redirected but there's no
particular harm in that.  In the future, we could not `fputs` when the
MOZ_LOG system will log the given message, but it seems better to
actually do the work to connect the `Log.jsm` and `ConsoleAPI.jsm`
systems to MOZ_LOG rather than continue to add work arounds.

Differential Revision: https://phabricator.services.mozilla.com/D104636
  • Loading branch information
ncalexan committed Feb 25, 2021
1 parent 1fe1bca commit 20e7116
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions dom/base/MessageManagerGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "mozilla/dom/MessageManagerGlobal.h"
#include "mozilla/IntentionalCrash.h"
#include "mozilla/Logging.h"
#include "nsContentUtils.h"
#include "nsJSUtils.h"

Expand All @@ -23,16 +24,18 @@ void MessageManagerGlobal::Dump(const nsAString& aStr) {
return;
}

NS_ConvertUTF16toUTF8 cStr(aStr);
MOZ_LOG(nsContentUtils::DOMDumpLog(), mozilla::LogLevel::Debug,
("[MessageManager.Dump] %s", cStr.get()));
#ifdef ANDROID
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s",
NS_ConvertUTF16toUTF8(aStr).get());
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", cStr.get());
#endif
#ifdef XP_WIN
if (IsDebuggerPresent()) {
OutputDebugStringW(PromiseFlatString(aStr).get());
}
#endif
fputs(NS_ConvertUTF16toUTF8(aStr).get(), stdout);
fputs(cStr.get(), stdout);
fflush(stdout);
}

Expand Down
4 changes: 3 additions & 1 deletion dom/worklet/WorkletGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mozilla/dom/WorkletImpl.h"
#include "mozilla/dom/WorkletThread.h"
#include "mozilla/dom/Console.h"
#include "nsContentUtils.h"
#include "nsJSUtils.h"

namespace mozilla {
Expand Down Expand Up @@ -80,10 +81,11 @@ void WorkletGlobalScope::Dump(const Optional<nsAString>& aString) const {

NS_ConvertUTF16toUTF8 str(aString.Value());

MOZ_LOG(nsContentUtils::DOMDumpLog(), mozilla::LogLevel::Debug,
("[Worklet.Dump] %s", str.get()));
#ifdef ANDROID
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", str.get());
#endif

fputs(str.get(), stdout);
fflush(stdout);
}
Expand Down
2 changes: 2 additions & 0 deletions js/xpconnect/loader/mozJSComponentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ static bool Dump(JSContext* cx, unsigned argc, Value* vp) {
return false;
}

MOZ_LOG(nsContentUtils::DOMDumpLog(), mozilla::LogLevel::Debug,
("[Backstage.Dump] %s", utf8str.get()));
#ifdef ANDROID
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", utf8str.get());
#endif
Expand Down
3 changes: 2 additions & 1 deletion js/xpconnect/src/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ static bool SandboxDump(JSContext* cx, unsigned argc, Value* vp) {
c++;
}
#endif
MOZ_LOG(nsContentUtils::DOMDumpLog(), mozilla::LogLevel::Debug,
("[Sandbox.Dump] %s", cstr));
#ifdef ANDROID
__android_log_write(ANDROID_LOG_INFO, "GeckoDump", cstr);
#endif

fputs(cstr, stdout);
fflush(stdout);
args.rval().setBoolean(true);
Expand Down

0 comments on commit 20e7116

Please sign in to comment.