[Scummvm-git-logs] scummvm master -> 4325e2db0021d8c3c5b2271177f01d0e07e204c4

sev- noreply at scummvm.org
Fri May 24 10:39:33 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4325e2db00 COMMON: Add a log watcher


Commit: 4325e2db0021d8c3c5b2271177f01d0e07e204c4
    https://github.com/scummvm/scummvm/commit/4325e2db0021d8c3c5b2271177f01d0e07e204c4
Author: scemino (scemino74 at gmail.com)
Date: 2024-05-24T12:39:29+02:00

Commit Message:
COMMON: Add a log watcher

Changed paths:
  A common/log.h
    common/debug.cpp
    common/system.h
    common/textconsole.cpp


diff --git a/common/debug.cpp b/common/debug.cpp
index 635065a03f7..113dc5b677a 100644
--- a/common/debug.cpp
+++ b/common/debug.cpp
@@ -184,12 +184,16 @@ bool debugChannelSet(int level, uint32 debugChannels) {
 
 #ifndef DISABLE_TEXT_CONSOLE
 
-static void debugHelper(const char *s, va_list va, bool caret = true) {
+static void debugHelper(const char *s, va_list va, int level, uint32 debugChannels, bool caret = true) {
 	Common::String buf = Common::String::vformat(s, va);
 
 	if (caret)
 		buf += '\n';
 
+	Common::LogWatcher logWatcher = Common::getLogWatcher();
+	if (logWatcher)
+   		(*logWatcher)(LogMessageType::kDebug, level, debugChannels, buf.c_str());
+
 	if (g_system)
 		g_system->logMessage(LogMessageType::kDebug, buf.c_str());
 	// TODO: Think of a good fallback in case we do not have
@@ -203,7 +207,7 @@ void debug(const char *s, ...) {
 		return;
 
 	va_start(va, s);
-	debugHelper(s, va);
+	debugHelper(s, va, 0, 0);
 	va_end(va);
 }
 
@@ -214,7 +218,7 @@ void debug(int level, const char *s, ...) {
 		return;
 
 	va_start(va, s);
-	debugHelper(s, va);
+	debugHelper(s, va, level, 0);
 	va_end(va);
 
 }
@@ -226,7 +230,7 @@ void debugN(const char *s, ...) {
 		return;
 
 	va_start(va, s);
-	debugHelper(s, va, false);
+	debugHelper(s, va, 0, 0, false);
 	va_end(va);
 }
 
@@ -237,7 +241,7 @@ void debugN(int level, const char *s, ...) {
 		return;
 
 	va_start(va, s);
-	debugHelper(s, va, false);
+	debugHelper(s, va, level, 0, false);
 	va_end(va);
 }
 
@@ -250,7 +254,7 @@ void debugC(int level, uint32 debugChannels, const char *s, ...) {
 			return;
 
 	va_start(va, s);
-	debugHelper(s, va);
+	debugHelper(s, va, level, debugChannels);
 	va_end(va);
 }
 
@@ -263,7 +267,7 @@ void debugCN(int level, uint32 debugChannels, const char *s, ...) {
 			return;
 
 	va_start(va, s);
-	debugHelper(s, va, false);
+	debugHelper(s, va, level, debugChannels, false);
 	va_end(va);
 }
 
@@ -276,7 +280,7 @@ void debugC(uint32 debugChannels, const char *s, ...) {
 			return;
 
 	va_start(va, s);
-	debugHelper(s, va);
+	debugHelper(s, va, 0, debugChannels);
 	va_end(va);
 }
 
@@ -289,7 +293,7 @@ void debugCN(uint32 debugChannels, const char *s, ...) {
 			return;
 
 	va_start(va, s);
-	debugHelper(s, va, false);
+	debugHelper(s, va, 0, debugChannels, false);
 	va_end(va);
 }
 
diff --git a/common/log.h b/common/log.h
new file mode 100644
index 00000000000..2e0c88f1475
--- /dev/null
+++ b/common/log.h
@@ -0,0 +1,64 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef COMMON_LOG_H
+#define COMMON_LOG_H
+
+#include "common/scummsys.h"
+
+namespace LogMessageType {
+/**
+ * Enumeration for log message types.
+ * @ingroup common_system
+ *
+ */
+enum Type {
+	kInfo,    /**< Info logs. */
+	kError,   /**< Error logs. */
+	kWarning, /**< Warning logs. */
+	kDebug    /**< Debug logs. */
+};
+
+} // End of namespace LogMessageType
+
+namespace Common {
+
+/**
+ * A callback that is invoked by debug, warning and error methods.
+ *
+ * A typical example would be a function that shows a debug
+ * console and displays the given message in it.
+ */
+typedef void (*LogWatcher)(LogMessageType::Type type, int level, uint32 debugChannels, const char *message);
+
+/**
+ * Set the watcher used by debug, error and warning methods.
+ */
+void setLogWatcher(LogWatcher f);
+
+/**
+ * Get the watcher used by debug, error and warning methods.
+ */
+LogWatcher getLogWatcher();
+
+} // namespace Common
+
+#endif
diff --git a/common/system.h b/common/system.h
index f4456d9579e..f3bba6a62f7 100644
--- a/common/system.h
+++ b/common/system.h
@@ -30,6 +30,7 @@
 #include "common/str-array.h" // For OSystem::updateStartSettings()
 #include "common/hash-str.h" // For OSystem::updateStartSettings()
 #include "common/path.h"
+#include "common/log.h"
 #include "graphics/pixelformat.h"
 #include "graphics/mode.h"
 #include "graphics/opengl/context.h"
@@ -112,21 +113,6 @@ struct TimeDate {
 	int tm_wday;    /**< Days since Sunday (0 - 6). */
 };
 
-namespace LogMessageType {
-/**
- * Enumeration for log message types.
- * @ingroup common_system
- *
- */
-enum Type {
-	kInfo,    /**< Info logs. */
-	kError,   /**< Error logs. */
-	kWarning, /**< Warning logs. */
-	kDebug    /**< Debug logs. */
-};
-
-} // End of namespace LogMessageType
-
 /**
 * Pixel mask modes for cursor graphics.
 */
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index eb74c505a66..88e6d7fcc65 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -33,6 +33,16 @@ void setErrorOutputFormatter(OutputFormatter f) {
 	s_errorOutputFormatter = f;
 }
 
+static LogWatcher s_logWatcher = nullptr;
+
+void setLogWatcher(LogWatcher f) {
+	s_logWatcher = f;
+}
+
+LogWatcher getLogWatcher() {
+	return s_logWatcher;
+}
+
 static ErrorHandler s_errorHandler = nullptr;
 
 void setErrorHandler(ErrorHandler handler) {
@@ -53,6 +63,9 @@ void warning(const char *s, ...) {
 	output = Common::String::vformat(s, va);
 	va_end(va);
 
+	if (Common::s_logWatcher)
+   		(*Common::s_logWatcher)(LogMessageType::kWarning, 0, 0, output.c_str());
+
 	output = "WARNING: " + output + "!\n";
 
 	if (g_system)
@@ -89,6 +102,9 @@ void NORETURN_PRE error(const char *s, ...) {
 	buf_output[STRINGBUFLEN - 1] = '\0';
 	Common::strcat_s(buf_output, "!\n");
 
+	if (Common::s_logWatcher)
+   		(*Common::s_logWatcher)(LogMessageType::kError, 0, 0, buf_output);
+
 	if (g_system)
 		g_system->logMessage(LogMessageType::kError, buf_output);
 	// TODO: Think of a good fallback in case we do not have




More information about the Scummvm-git-logs mailing list