Browse Source

The new logger is implemented

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
958da90ba4

File diff suppressed because it is too large
+ 0 - 0
build/debug/Makefile


+ 9 - 10
src/Core/App.cpp

@@ -10,9 +10,8 @@
 #include "MainRenderer.h"
 #include "ScriptingEngine.h"
 #include "StdinListener.h"
-#include "MessageHandler.h"
-#include "Messaging.h"
 #include "Input.h"
+#include "Logger.h"
 
 
 App* app = NULL; ///< The only global var. App constructor sets it
@@ -76,9 +75,8 @@ App::App(int argc, char* argv[], Object* parent):
 
 	parseCommandLineArgs(argc, argv);
 
-	messageHandler = new MessageHandler(this);
 	// send output to handleMessageHanlderMsgs
-	messageHandler->getSignal().connect(boost::bind(&App::handleMessageHanlderMsgs, this, _1, _2, _3, _4));
+	Logger::getInstance().getSignal().connect(boost::bind(&App::handleMessageHanlderMsgs, this, _1, _2, _3, _4));
 
 	printAppInfo();
 
@@ -93,23 +91,24 @@ App::App(int argc, char* argv[], Object* parent):
 	settingsPath = boost::filesystem::path(getenv("HOME")) / ".anki";
 	if(!boost::filesystem::exists(settingsPath))
 	{
-		INFO("Creating settings dir \"" + settingsPath.string() + "\"");
+		INFO("Creating settings dir \"" << settingsPath.string() << "\"");
 		boost::filesystem::create_directory(settingsPath);
 	}
 
 	cachePath = settingsPath / "cache";
 	if(boost::filesystem::exists(cachePath))
 	{
-		INFO("Deleting dir \"" + cachePath.string() + "\"");
+		INFO("Deleting dir \"" << cachePath.string() << "\"");
 		boost::filesystem::remove_all(cachePath);
 	}
 
-	INFO("Creating cache dir \"" + cachePath.string() + "\"");
+	INFO("Creating cache dir \"" << cachePath.string() << "\"");
 	boost::filesystem::create_directory(cachePath);
 
 	// create the subsystems. WATCH THE ORDER
 	scriptingEngine = new ScriptingEngine(this);
 	scriptingEngine->exposeVar("app", this);
+	/// @todo
 	const char* commonPythonCode =
 	"import sys\n"
 	"from Anki import *\n"
@@ -119,14 +118,14 @@ App::App(int argc, char* argv[], Object* parent):
 	"\t\tline = sys._getframe(1).f_lineno\n"
 	"\t\tfile = sys._getframe(1).f_code.co_filename\n"
 	"\t\tfunc = sys._getframe(1).f_code.co_name\n"
-	"\t\tapp.getMessageHandler().write(file, line, func, str_)\n"
+	"\t\tLogger.getInstance().write(file, line, func, str_)\n"
 	"\n"
 	"class StderrCatcher:\n"
 	"\tdef write(self, str_):\n"
 	"\t\tline = sys._getframe(2).f_lineno\n"
 	"\t\tfile = sys._getframe(2).f_code.co_filename\n"
 	"\t\tfunc = sys._getframe(2).f_code.co_name\n"
-	"\t\tapp.getMessageHandler().write(file, line, func, str_)\n"
+	"\t\tLogger.getInstance().write(file, line, func, str_)\n"
 	"\n"
 	"sys.stdout = StdoutCatcher()\n"
 	"sys.stderr = StderrCatcher()\n";
@@ -161,7 +160,7 @@ void App::initWindow()
 	const char* driverName = SDL_GetCurrentVideoDriver();
 	if(driverName != NULL)
 	{
-		INFO("Video driver name: " + driverName);
+		INFO("Video driver name: " << driverName);
 	}
 
 	// set GL attribs

+ 0 - 10
src/Core/App.h

@@ -4,7 +4,6 @@
 #include <SDL/SDL.h>
 #include <boost/filesystem.hpp>
 #include "Object.h"
-#include "MessageHandler.h"
 #include "StdTypes.h"
 #include "Properties.h"
 #include "Exception.h"
@@ -60,7 +59,6 @@ class App: public Object
 		MainRenderer& getMainRenderer();
 		Camera* getActiveCam() {return activeCam;}
 		void setActiveCam(Camera* cam) {activeCam = cam;}
-		MessageHandler& getMessageHandler();
 		Input& getInput();
 		/// @}
 
@@ -83,7 +81,6 @@ class App: public Object
 		ScriptingEngine* scriptingEngine;
 		MainRenderer* mainRenderer;
 		StdinListener* stdinListener;
-		MessageHandler* messageHandler;
 		Input* input;
 		/// @}
 
@@ -128,13 +125,6 @@ inline MainRenderer& App::getMainRenderer()
 }
 
 
-inline MessageHandler& App::getMessageHandler()
-{
-	RASSERT_THROW_EXCEPTION(messageHandler == NULL);
-	return *messageHandler;
-}
-
-
 inline Input& App::getInput()
 {
 	RASSERT_THROW_EXCEPTION(input == NULL);

+ 25 - 5
src/Core/Logger.cpp

@@ -1,4 +1,4 @@
-#include <cstdio>
+#include <cstring>
 #include "Logger.h"
 
 
@@ -15,12 +15,21 @@ Logger& Logger::operator<<(const char* val)
 }
 
 
+//======================================================================================================================
+// operator<< [std::string]                                                                                            =
+//======================================================================================================================
+Logger& Logger::operator<<(const std::string& val)
+{
+	append(val.c_str(), val.length());
+	return *this;
+}
+
+
 //======================================================================================================================
 // operator<< [Logger& (*funcPtr)(Logger&)]                                                                            =
 //======================================================================================================================
 Logger& Logger::operator<<(Logger& (*funcPtr)(Logger&))
 {
-	printf("Got some func\n");
 	if(funcPtr == endl)
 	{
 		append("\n", 1);
@@ -31,7 +40,7 @@ Logger& Logger::operator<<(Logger& (*funcPtr)(Logger&))
 
 
 //======================================================================================================================
-//                                                                                                                     =
+// operator<< [LoggerSender]                                                                                           =
 //======================================================================================================================
 Logger& Logger::operator<<(const LoggerSender& sender)
 {
@@ -42,6 +51,19 @@ Logger& Logger::operator<<(const LoggerSender& sender)
 }
 
 
+//======================================================================================================================
+// write                                                                                                               =
+//======================================================================================================================
+void Logger::write(const char* file_, int line_, const char* func_, const char* msg)
+{
+	file = file_;
+	line = line_;
+	func = func_;
+	append(msg, strlen(msg));
+	flush();
+}
+
+
 //======================================================================================================================
 // execCommonConstructionCode                                                                                          =
 //======================================================================================================================
@@ -94,6 +116,4 @@ void Logger::flush()
 	sptr = &streamBuf[0];
 	func = file = "error";
 	line = -1;
-
-	printf("Flushing: |%s|\n", &streamBuf[0]);
 }

+ 36 - 7
src/Core/Logger.h

@@ -13,10 +13,14 @@ struct LoggerSender;
 class Logger
 {
 	public:
-		typedef boost::signals2::signal<void (const char*, int, const char*, const char*)> Signal;
+		typedef boost::signals2::signal<void (const char*, int, const char*, const char*)> Signal; ///< Signal type
 
+		/// Singleton stuff
 		static Logger& getInstance();
 
+		/// Accessor
+		Signal& getSignal() {return sig;}
+
 		/// @name Numeric operators
 		/// @{
 		Logger& operator<<(const bool& val) {return appendUsingLexicalCast(val);}
@@ -33,18 +37,22 @@ class Logger
 
 		Logger& operator<<(const void* val);
 		Logger& operator<<(const char* val);
+		Logger& operator<<(const std::string& val);
 		Logger& operator<<(Logger& (*funcPtr)(Logger&));
 		Logger& operator<<(const LoggerSender& sender);
 
+		/// An alternative method to write in the Logger
+		void write(const char* file, int line, const char* func, const char* msg);
+
 	private:
-		static Logger* instance;
-		static const int STREAM_SIZE = 25;
+		static Logger* instance; ///< Singleton stuff
+		static const int STREAM_SIZE = 512;
 		boost::array<char, STREAM_SIZE> streamBuf;
 		char* sptr; ///< Pointer to @ref streamBuf
 		Signal sig; ///< The signal
-		const char* func;
-		const char* file;
-		int line;
+		const char* func; ///< Sender info
+		const char* file; ///< Sender info
+		int line; ///< Sender info
 
 		/// @name Ensure its singleton
 		/// @{
@@ -62,11 +70,16 @@ class Logger
 		/// Append finalize streamBuf and send the signal
 		void flush();
 
+		/// Because we are bored to write
 		template<typename Type>
 		Logger& appendUsingLexicalCast(const Type& val);
 };
 
 
+//======================================================================================================================
+// Inlines                                                                                                             =
+//======================================================================================================================
+
 inline Logger& Logger::getInstance()
 {
 	if(instance == NULL)
@@ -105,6 +118,7 @@ inline Logger& endl(Logger& logger)
 }
 
 
+/// Record the sender
 struct LoggerSender
 {
 	const char* file;
@@ -112,7 +126,8 @@ struct LoggerSender
 	const char* func;
 };
 
-///
+
+/// Help the Logger to set the sender
 inline LoggerSender setSender(const char* file, int line, const char* func)
 {
 	LoggerSender sender = {file, line, func};
@@ -120,4 +135,18 @@ inline LoggerSender setSender(const char* file, int line, const char* func)
 }
 
 
+//======================================================================================================================
+// Macros                                                                                                              =
+//======================================================================================================================
+
+#define LOGGER_MESSAGE(x) \
+	Logger::getInstance()  << setSender(__FILE__, __LINE__, __func__) << x << endl;
+
+#define INFO(x) LOGGER_MESSAGE("Info: " << x)
+
+#define WARNING(x) LOGGER_MESSAGE("Warning: " << x)
+
+#define ERROR(x) LOGGER_MESSAGE("Error: " << x)
+
+
 #endif

+ 0 - 33
src/Core/MessageHandler.h

@@ -1,33 +0,0 @@
-#ifndef MESSAGE_HANDLER_H
-#define MESSAGE_HANDLER_H
-
-#include <boost/signals2.hpp>
-#include <string>
-#include "Object.h"
-
-
-/// A generic message handler.
-/// Using @ref write method you send a message to the slots connected to @ref sig signal
-class MessageHandler: public Object
-{
-	public:
-		typedef boost::signals2::signal<void (const char*, int, const char*, const std::string&)> Signal;
-
-		MessageHandler(Object* parent = NULL): Object(parent) {}
-
-		/// Emmits a message to the slots connected to @ref sig. A simple wrapper to hide the signal
-		/// @param file Who send the message
-		/// @param line Who send the message
-		/// @param func Who send the message
-		/// @param msg The message to emmit
-		void write(const char* file, int line, const char* func, const std::string& msg) {sig(file, line, func, msg);}
-
-		/// Accessor
-		Signal& getSignal() {return sig;}
-
-	private:
-		Signal sig; ///< The signal
-};
-
-
-#endif

+ 0 - 19
src/Core/Messaging.h

@@ -1,19 +0,0 @@
-#ifndef MESSAGING_H
-#define MESSAGING_H
-
-#include <string>
-#include "App.h"
-#include "MessageHandler.h"
-
-
-#define MESSAGE(x) \
-	app->getMessageHandler().write(__FILE__, __LINE__, __func__, std::string() + x)
-
-#define INFO(x) MESSAGE(std::string("Info: ") + x)
-
-#define WARNING(x) MESSAGE(std::string("Warning: ") + x)
-
-#define ERROR(x) MESSAGE(std::string("Error: ") + x)
-
-
-#endif

+ 3 - 9
src/Main.cpp

@@ -30,7 +30,6 @@
 #include "RigidBody.h"
 #include "ScriptingEngine.h"
 #include "StdinListener.h"
-#include "Messaging.h"
 #include "ModelNode.h"
 #include "SkelAnimModelNodeCtrl.h"
 #include "Model.h"
@@ -250,7 +249,7 @@ void init()
 
 	initPhysics();
 
-	INFO("Engine initialization ends (" + boost::lexical_cast<std::string>(App::getTicks() - ticks) + ")");
+	INFO("Engine initialization ends (" << (App::getTicks() - ticks) << ")");
 }
 
 
@@ -376,7 +375,7 @@ void mainLoop()
 		}
 	}while(true);
 
-	INFO("Exiting main loop (" + boost::lexical_cast<std::string>(App::getTicks() - ticks) + ")");
+	INFO("Exiting main loop (" << (App::getTicks() - ticks) << ")");
 }
 
 
@@ -385,11 +384,6 @@ void mainLoop()
 //======================================================================================================================
 int main(int argc, char* argv[])
 {
-	//std::stringstream ss;
-	Logger::getInstance()  << setSender(__FILE__, __LINE__, __func__) << "123456789 " << 1.23 << "+++" << endl;
-
-	return 0;
-
 	try
 	{
 		new App(argc, argv);
@@ -403,7 +397,7 @@ int main(int argc, char* argv[])
 	}
 	catch(std::exception& e)
 	{
-		ERROR("Aborting: " + e.what());
+		ERROR("Aborting: " << e.what());
 		//abort();
 		return 1;
 	}

+ 3 - 3
src/Renderer/MainRenderer.cpp

@@ -8,8 +8,8 @@
 #include "MainRenderer.h"
 #include "App.h"
 #include "RendererInitializer.h"
-#include "Messaging.h"
 #include "Ssao.h"
+#include "Logger.h"
 
 
 //======================================================================================================================
@@ -48,8 +48,8 @@ void MainRenderer::initGl()
 	glGetError();
 
 	// print GL info
-	INFO("OpenGL info: OGL " + reinterpret_cast<const char*>(glGetString(GL_VERSION)) + ", GLSL " +
-	     reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION)));
+	INFO("OpenGL info: OGL " << reinterpret_cast<const char*>(glGetString(GL_VERSION)) <<
+	     ", GLSL " << reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION)));
 
 	// get max texture units
 	//glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAtachments);

+ 1 - 1
src/Renderer/PhyDbgDrawer.cpp

@@ -2,7 +2,7 @@
 #include "MainRenderer.h"
 #include "App.h"
 #include "BtAndAnkiConvertors.h"
-#include "Messaging.h"
+#include "Logger.h"
 
 
 //======================================================================================================================

+ 1 - 1
src/Resources/Core/RsrcContainer.inl.h

@@ -2,7 +2,7 @@
 #include <boost/lexical_cast.hpp>
 #include "RsrcContainer.h"
 #include "Exception.h"
-#include "Messaging.h"
+#include "Logger.h"
 
 
 //======================================================================================================================

+ 3 - 3
src/Resources/ShaderProg.cpp

@@ -5,7 +5,7 @@
 #include "ShaderPrePreprocessor.h"
 #include "App.h" // To get cache dir
 #include "GlException.h"
-#include "Messaging.h"
+#include "Logger.h"
 
 
 #define SPROG_EXCEPTION(x) EXCEPTION("Shader prog \"" + getRsrcName() + "\": " + x)
@@ -126,7 +126,7 @@ void ShaderProg::getUniAndAttribVars()
 		int loc = glGetAttribLocation(glId, name_);
 		if(loc == -1) // if -1 it means that its an FFP var
 		{
-			WARNING("Shader prog: \"" + getRsrcName() + "\": You are using FFP vertex attributes (\"" + name_ + "\")");
+			WARNING("Shader prog: \"" << getRsrcName() << "\": You are using FFP vertex attributes (\"" << name_ << "\")");
 			continue;
 		}
 
@@ -147,7 +147,7 @@ void ShaderProg::getUniAndAttribVars()
 		int loc = glGetUniformLocation(glId, name_);
 		if(loc == -1) // if -1 it means that its an FFP var
 		{
-			WARNING("Shader prog: \"" + getRsrcName() + "\": You are using FFP vertex uniforms (\"" + name_ + "\")");
+			WARNING("Shader prog: \"" << getRsrcName() << "\": You are using FFP vertex uniforms (\"" << name_ << "\")");
 			continue;
 		}
 

+ 0 - 2
src/Scripting/BoostPythonInterfaces.cpp

@@ -19,7 +19,5 @@ BOOST_PYTHON_MODULE(Anki)
 	CALL_WRAP(Dbg)
 	CALL_WRAP(MainRenderer)
 
-	CALL_WRAP(MessageHandler)
-
 	CALL_WRAP(App)
 }

+ 0 - 1
src/Scripting/Core/App.bpi.cpp

@@ -9,7 +9,6 @@ WRAP(App)
 	class_<App, noncopyable>("App", no_init)
 		.def("getScene", &App::getScene, return_value_policy<reference_existing_object>())
 		.def("getMainRenderer", &App::getMainRenderer, return_value_policy<reference_existing_object>())
-		.def("getMessageHandler", &App::getMessageHandler, return_value_policy<reference_existing_object>())
 		.def("quit", &App::quit)
 	;
 }

+ 12 - 0
src/Scripting/Core/Logger.bpi.cpp

@@ -0,0 +1,12 @@
+#include "ScriptingCommon.h"
+#include "Logger.h"
+
+
+WRAP(Logger)
+{
+	class_<Logger, noncopyable>("Logger", no_init)
+		.def("getInstance", &Logger::getInstance, return_value_policy<reference_existing_object>())
+		.staticmethod("getInstance")
+		.def("write", &Logger::write)
+	;
+}

+ 0 - 10
src/Scripting/Core/MessageHandler.bpi.cpp

@@ -1,10 +0,0 @@
-#include "ScriptingCommon.h"
-#include "MessageHandler.h"
-
-
-WRAP(MessageHandler)
-{
-	class_<MessageHandler, noncopyable>("MessageHandler", no_init)
-		.def("write", &MessageHandler::write)
-	;
-}

Some files were not shown because too many files changed in this diff