/[Sims3RigEditor]/trunk/gr2lib_cpp/GrannyAPILogger.cpp
ViewVC logotype

Diff of /trunk/gr2lib_cpp/GrannyAPILogger.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib_cpp/GrannyAPILogger.cpp	2010/07/31 01:44:00	7
+++ trunk/gr2lib_cpp/GrannyAPILogger.cpp	2010/07/31 09:33:11	12
@@ -1,6 +1,12 @@
 #include "StdAfx.h"
 #include "GrannyAPILogger.h"
-
+#include "guicon.h"
+#include "VSDebugOutput.h"
+#include <sys/stat.h>
+#include <ostream>
+#include <sstream>
+#include <string>
+using namespace System::Runtime::InteropServices;
 void __cdecl  Callback(granny_log_message_type Type, granny_log_message_origin Origin, char const * Message, void * UserData);
 
 GrannyAPILogger::GrannyAPILogger(void)
@@ -8,10 +14,84 @@
 	granny_log_callback NewCallback;
 	NewCallback.Function = Callback;
 	NewCallback.UserData = NULL;
+	// set Granny2 log function
 	GrannySetLogCallback(&NewCallback);
 }
+void GrannyAPILogger::SetLogFileName(const char* filename)
+{
+	System::IO::FileInfo^ fs = gcnew System::IO::FileInfo(gcnew System::String(filename));
+	//System::String^ _filename_no_ext = fs->Name->Remove( fs->Name->Length -  fs->Extension->Length);
+	const char* _const_filename_no_ext = (char*)(void*)Marshal::StringToHGlobalAnsi(fs->Name->ToLower());
+	const char* log_suffix = ".log";
+	int msg_malloc = (strlen(_const_filename_no_ext) + strlen(log_suffix));
+
+		char* msg = (char*)malloc(msg_malloc);
+		for (int i=0; i<msg_malloc; i++) {
+			msg[i] = 0;    // Initialize all elements to zero.
+		}
 
+		strcat(msg,_const_filename_no_ext);
+		strcat(msg,log_suffix);
+	// set Granny2 log file
+	GrannySetLogFileName(msg,true);
+}
+void GrannyAPILogger::SetLogFileName(const char* logpath,const char* filename)
+{
+	
+	if (!System::IO::Directory::Exists(gcnew System::String(logpath)))
+	{
+		System::IO::Directory::CreateDirectory(gcnew System::String(logpath));
+	}
+
+	System::IO::FileInfo^ fs = gcnew System::IO::FileInfo(gcnew System::String(filename));
+	//System::String^ _filename_no_ext = fs->Name->Remove( fs->Name->Length -  fs->Extension->Length);
+	const char* _const_filename_no_ext = (char*)(void*)Marshal::StringToHGlobalAnsi(fs->Name->ToLower());
+	const char* log_suffix = ".log";
+	int msg_malloc = (strlen(logpath) + strlen(_const_filename_no_ext) + strlen(log_suffix));
+
+		char* msg = (char*)malloc(msg_malloc);
+		for (int i=0; i<msg_malloc; i++) {
+			msg[i] = 0;    // Initialize all elements to zero.
+		}
+		strcat(msg,logpath);
+		strcat(msg,"\\");
+		strcat(msg,_const_filename_no_ext);
+		strcat(msg,log_suffix);
+	// set Granny2 log file
+		GrannySetLogFileName(msg,true);
+}
 void __cdecl Callback(granny_log_message_type Type, granny_log_message_origin Origin, char const * Message, void * UserData)
 {
-	assert(Message);
-}
\ No newline at end of file
+	char const* TypeString = GrannyGetLogMessageTypeString(Type);
+	char const* OriginString = GrannyGetLogMessageOriginString(Origin);
+
+	printf("\n\n\tGranny2 API Logger: Logging Granny2 Message ->\n\t\tMessage Log Type: %s\n\t\tMessage Log Origin: %s\n\t\tMessage: %s",
+		TypeString,
+		OriginString,
+		Message);
+
+	VSDebugWriterW VSDebugWriter;
+
+	VSDebugWriter 
+		<< "\n\n\tGranny2 API Logger: Logging Granny2 Message ->"
+		<< "\n\t\tMessage Log Type: " << TypeString
+		<< "\n\t\tMessage Log Origin: " << OriginString
+		<< "\n\t\tMessage: " << Message;
+}
+
+void GrannyAPILogger::LogMessage(const char* Message)
+{
+	//printf("\n\tGranny2 API Logger: Logging Application Message ->\n\t\tMessage: %s",Message);
+	printf("\n\t%s",Message);
+
+	VSDebugWriterW VSDebugWriter;
+
+	VSDebugWriter << "\n\t" << Message;
+		/*<< "\n\tGranny2 API Logger: Application Message ->"
+		<< "\n\t\tMessage: " << Message;*/
+}
+void GrannyAPILogger::LogDebugMessageOnly(const char* Message)
+{	
+	VSDebugWriterW VSDebugWriter;
+	VSDebugWriter << Message;
+}

 

  ViewVC Help
Powered by ViewVC 1.1.22