MMPrinter.h (1851B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MMPrinter_h 8 #define MMPrinter_h 9 10 #include "mozilla/Maybe.h" 11 #include "mozilla/UniquePtr.h" 12 #include "mozilla/dom/DOMTypes.h" 13 #include "nsString.h" 14 15 namespace mozilla::dom { 16 17 class MMPrinter { 18 public: 19 static void Print(char const* aLocation, const nsAString& aMsg, 20 ClonedMessageData const& aData) { 21 if (MOZ_UNLIKELY(MOZ_LOG_TEST(MMPrinter::sMMLog, LogLevel::Debug))) { 22 Maybe<uint64_t> msgId = MMPrinter::PrintHeader(aLocation, aMsg); 23 if (!msgId.isSome()) { 24 return; 25 } 26 MMPrinter::PrintData(*msgId, aData); 27 } 28 } 29 30 static void Print(char const* aLocation, const nsACString& aActorName, 31 const nsAString& aMessageName, 32 const UniquePtr<ClonedMessageData>& aData) { 33 if (MOZ_UNLIKELY(MOZ_LOG_TEST(MMPrinter::sMMLog, LogLevel::Debug))) { 34 Maybe<uint64_t> msgId = MMPrinter::PrintHeader( 35 aLocation, 36 NS_ConvertUTF8toUTF16(aActorName + " - "_ns) + aMessageName); 37 38 if (!msgId.isSome()) { 39 return; 40 } 41 42 if (aData) { 43 MMPrinter::PrintData(*msgId, *aData); 44 } else { 45 MMPrinter::PrintNoData(*msgId); 46 } 47 } 48 } 49 50 private: 51 static LazyLogModule sMMLog; 52 static Maybe<uint64_t> PrintHeader(char const* aLocation, 53 const nsAString& aMsg); 54 static void PrintNoData(uint64_t aMsgId); 55 static void PrintData(uint64_t aMsgId, ClonedMessageData const& aData); 56 }; 57 58 } // namespace mozilla::dom 59 60 #endif /* MMPrinter_h */