From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/webrtc/common/browser_logging/CSFLog.cpp | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 dom/media/webrtc/common/browser_logging/CSFLog.cpp (limited to 'dom/media/webrtc/common/browser_logging/CSFLog.cpp') diff --git a/dom/media/webrtc/common/browser_logging/CSFLog.cpp b/dom/media/webrtc/common/browser_logging/CSFLog.cpp new file mode 100644 index 0000000000..d58f5726a5 --- /dev/null +++ b/dom/media/webrtc/common/browser_logging/CSFLog.cpp @@ -0,0 +1,85 @@ +/* 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 +#include +#include + +#include "CSFLog.h" + +#include +#include "prrwlock.h" +#include "prthread.h" +#include "nsThreadUtils.h" + +#include "mozilla/Logging.h" +#include "mozilla/Sprintf.h" + +mozilla::LazyLogModule gSignalingLog("signaling"); + +void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine, + const char* tag, const char* format, va_list args) { +#ifdef STDOUT_LOGGING + printf("%s\n:", tag); + vprintf(format, args); +#else + + mozilla::LogLevel level = + static_cast(static_cast(priority)); + + // Skip doing any of this work if we're not logging the indicated level... + if (!MOZ_LOG_TEST(gSignalingLog, level)) { + return; + } + + // Trim the path component from the filename + const char* lastSlash = sourceFile; + while (*sourceFile) { + if (*sourceFile == '/' || *sourceFile == '\\') { + lastSlash = sourceFile; + } + sourceFile++; + } + sourceFile = lastSlash; + if (*sourceFile == '/' || *sourceFile == '\\') { + sourceFile++; + } + +# define MAX_MESSAGE_LENGTH 1024 + char message[MAX_MESSAGE_LENGTH]; + + const char* threadName = NULL; + + // Check if we're the main thread... + if (NS_IsMainThread()) { + threadName = "main"; + } else { + threadName = PR_GetThreadName(PR_GetCurrentThread()); + } + + // If we can't find it anywhere, use a blank string + if (!threadName) { + threadName = ""; + } + + VsprintfLiteral(message, format, args); + MOZ_LOG( + gSignalingLog, level, + ("[%s|%s] %s:%d: %s", threadName, tag, sourceFile, sourceLine, message)); +#endif +} + +void CSFLog(CSFLogLevel priority, const char* sourceFile, int sourceLine, + const char* tag, const char* format, ...) { + va_list ap; + va_start(ap, format); + + CSFLogV(priority, sourceFile, sourceLine, tag, format, ap); + va_end(ap); +} + +int CSFLogTestLevel(CSFLogLevel priority) { + return MOZ_LOG_TEST(gSignalingLog, static_cast( + static_cast(priority))); +} -- cgit v1.2.3