[sword-svn] r1928 - in trunk: include src/frontend src/modules/filters

scribe at crosswire.org scribe at crosswire.org
Sat Jun 10 17:07:33 MST 2006


Author: scribe
Date: 2006-06-10 17:07:30 -0700 (Sat, 10 Jun 2006)
New Revision: 1928

Modified:
   trunk/include/swlog.h
   trunk/src/frontend/swlog.cpp
   trunk/src/modules/filters/osiswordjs.cpp
   trunk/src/modules/filters/thmlheadings.cpp
Log:
Added better support for swlog subclassing


Modified: trunk/include/swlog.h
===================================================================
--- trunk/include/swlog.h	2006-06-07 04:20:06 UTC (rev 1927)
+++ trunk/include/swlog.h	2006-06-11 00:07:30 UTC (rev 1928)
@@ -29,7 +29,6 @@
 SWORD_NAMESPACE_START
 
 class SWDLLEXPORT SWLog {
-	friend class __staticsystemLog;
 protected:
 	char logLevel;
 	static SWLog *systemLog;
@@ -39,15 +38,19 @@
 	static SWLog *getSystemLog();
 	static void setSystemLog(SWLog *newLogger);
 
-	SWLog () { logLevel = 1;	/*default to show only errors*/}
+	SWLog() { logLevel = 1;	/*default to show only errors*/}
 	virtual ~SWLog() {};
 
-	virtual void setLogLevel(char level) { logLevel = level; }
-	virtual char getLogLevel() { return logLevel; }
-	virtual void logWarning (char *fmt, ...);
-	virtual void logError (char *fmt, ...);
-	virtual void logTimedInformation (char *fmt, ...);
-	virtual void logInformation (char *fmt, ...);
+	void setLogLevel(char level) { logLevel = level; }
+	char getLogLevel() const { return logLevel; }
+	void logWarning(const char *fmt, ...) const;
+	void logError(const char *fmt, ...) const;
+	void logInformation(const char *fmt, ...) const;
+
+	virtual void logTimedInformation(const char *fmt, ...) const;
+
+	// Override this method if you want to have a custom logger
+	virtual void logMessage(const char *message, int level) const;
 };
 
 SWORD_NAMESPACE_END

Modified: trunk/src/frontend/swlog.cpp
===================================================================
--- trunk/src/frontend/swlog.cpp	2006-06-07 04:20:06 UTC (rev 1927)
+++ trunk/src/frontend/swlog.cpp	2006-06-11 00:07:30 UTC (rev 1928)
@@ -15,16 +15,18 @@
 
 SWORD_NAMESPACE_START
 
+
 SWLog *SWLog::systemLog = 0;
 
-class __staticsystemLog {
-public:
-	__staticsystemLog() { }
-	~__staticsystemLog() { delete SWLog::systemLog; }
-} _staticsystemLog;
 
-
 SWLog *SWLog::getSystemLog() {
+	static class __staticSystemLog {
+	SWLog **clear;
+	public:
+		__staticSystemLog(SWLog **clear) { this->clear = clear; }
+		~__staticSystemLog() { delete *clear; *clear = 0; }
+	} _staticSystemLog(&SWLog::systemLog);
+
 	if (!systemLog)
 		systemLog = new SWLog();
 
@@ -33,13 +35,12 @@
 
 
 void SWLog::setSystemLog(SWLog *newLog) {
-	if (systemLog)
-		delete systemLog;
+	delete getSystemLog();
 	systemLog = newLog;
 }
 
 
-void SWLog::logWarning(char *fmt, ...) {
+void SWLog::logWarning(const char *fmt, ...) const {
 	char msg[2048];
 	va_list argptr;
 
@@ -47,16 +48,12 @@
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-
-#ifndef _WIN32_WCE
-		std::cerr << msg;
-		std::cerr << std::endl;
-#endif
+		logMessage(msg, 2);
 	}
 }
 
 
-void SWLog::logError(char *fmt, ...) {
+void SWLog::logError(const char *fmt, ...) const {
 	char msg[2048];
 	va_list argptr;
 
@@ -64,16 +61,12 @@
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-
-#ifndef _WIN32_WCE
-		std::cerr << msg;
-		std::cerr << std::endl;
-#endif
+		logMessage(msg, 1);
 	}
 }
 
 
-void SWLog::logTimedInformation(char *fmt, ...) {
+void SWLog::logTimedInformation(const char *fmt, ...) const {
 	char msg[2048];
 	va_list argptr;
 
@@ -81,16 +74,12 @@
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-
-#ifndef _WIN32_WCE
-		std::cout << msg;
-		std::cout << std::endl;
-#endif
+		logMessage(msg, 4);
 	}
 }
 
 
-void SWLog::logInformation(char *fmt, ...) {
+void SWLog::logInformation(const char *fmt, ...) const {
 	char msg[2048];
 	va_list argptr;
 
@@ -98,12 +87,12 @@
 		va_start(argptr, fmt);
 		vsprintf(msg, fmt, argptr);
 		va_end(argptr);
-
-#ifndef _WIN32_WCE
-		std::cout << msg;
-		std::cout << std::endl;
-#endif
+		logMessage(msg, 3);
 	}
 }
 
+void SWLog::logMessage(const char *message, int level) const {
+	std::cerr << message;
+	std::cerr << std::endl;
+}
 SWORD_NAMESPACE_END

Modified: trunk/src/modules/filters/osiswordjs.cpp
===================================================================
--- trunk/src/modules/filters/osiswordjs.cpp	2006-06-07 04:20:06 UTC (rev 1927)
+++ trunk/src/modules/filters/osiswordjs.cpp	2006-06-11 00:07:30 UTC (rev 1928)
@@ -6,6 +6,7 @@
 
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <osiswordjs.h>
 #include <swmodule.h>
 #include <ctype.h>

Modified: trunk/src/modules/filters/thmlheadings.cpp
===================================================================
--- trunk/src/modules/filters/thmlheadings.cpp	2006-06-07 04:20:06 UTC (rev 1927)
+++ trunk/src/modules/filters/thmlheadings.cpp	2006-06-11 00:07:30 UTC (rev 1928)
@@ -6,6 +6,7 @@
 
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <thmlheadings.h>
 #include <utilxml.h>
 #include <utilstr.h>



More information about the sword-cvs mailing list