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

Annotation of /trunk/gr2lib_cpp/GrannyAPILogger.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (hide annotations) (download)
Sat Jul 31 09:39:55 2010 UTC (10 years, 3 months ago) by william
File size: 3481 byte(s)
When calling -> GrannyAPILogger::SetLogFileName(const char* filename)
**Make sure to place the logfile in the same location as the source file.
So If the the file were: c:\example\something.gr2 -> c:\example\something.gr2.log
rather than %ApplicationPath%\something.gr2.log

1 william 6 #include "StdAfx.h"
2     #include "GrannyAPILogger.h"
3 william 12 #include "guicon.h"
4     #include "VSDebugOutput.h"
5     #include <sys/stat.h>
6     #include <ostream>
7     #include <sstream>
8     #include <string>
9     using namespace System::Runtime::InteropServices;
10 william 7 void __cdecl Callback(granny_log_message_type Type, granny_log_message_origin Origin, char const * Message, void * UserData);
11    
12 william 6 GrannyAPILogger::GrannyAPILogger(void)
13     {
14     granny_log_callback NewCallback;
15 william 7 NewCallback.Function = Callback;
16     NewCallback.UserData = NULL;
17 william 12 // set Granny2 log function
18 william 7 GrannySetLogCallback(&NewCallback);
19 william 6 }
20 william 12 void GrannyAPILogger::SetLogFileName(const char* filename)
21     {
22     System::IO::FileInfo^ fs = gcnew System::IO::FileInfo(gcnew System::String(filename));
23     //System::String^ _filename_no_ext = fs->Name->Remove( fs->Name->Length - fs->Extension->Length);
24 william 13 const char* _const_filename_no_ext = (char*)(void*)Marshal::StringToHGlobalAnsi(fs->FullName->ToLower());
25 william 12 const char* log_suffix = ".log";
26     int msg_malloc = (strlen(_const_filename_no_ext) + strlen(log_suffix));
27 william 6
28 william 12 char* msg = (char*)malloc(msg_malloc);
29     for (int i=0; i<msg_malloc; i++) {
30     msg[i] = 0; // Initialize all elements to zero.
31     }
32    
33     strcat(msg,_const_filename_no_ext);
34     strcat(msg,log_suffix);
35     // set Granny2 log file
36     GrannySetLogFileName(msg,true);
37     }
38     void GrannyAPILogger::SetLogFileName(const char* logpath,const char* filename)
39     {
40    
41     if (!System::IO::Directory::Exists(gcnew System::String(logpath)))
42     {
43     System::IO::Directory::CreateDirectory(gcnew System::String(logpath));
44     }
45    
46     System::IO::FileInfo^ fs = gcnew System::IO::FileInfo(gcnew System::String(filename));
47     //System::String^ _filename_no_ext = fs->Name->Remove( fs->Name->Length - fs->Extension->Length);
48     const char* _const_filename_no_ext = (char*)(void*)Marshal::StringToHGlobalAnsi(fs->Name->ToLower());
49     const char* log_suffix = ".log";
50     int msg_malloc = (strlen(logpath) + strlen(_const_filename_no_ext) + strlen(log_suffix));
51    
52     char* msg = (char*)malloc(msg_malloc);
53     for (int i=0; i<msg_malloc; i++) {
54     msg[i] = 0; // Initialize all elements to zero.
55     }
56     strcat(msg,logpath);
57     strcat(msg,"\\");
58     strcat(msg,_const_filename_no_ext);
59     strcat(msg,log_suffix);
60     // set Granny2 log file
61     GrannySetLogFileName(msg,true);
62     }
63 william 7 void __cdecl Callback(granny_log_message_type Type, granny_log_message_origin Origin, char const * Message, void * UserData)
64 william 6 {
65 william 12 char const* TypeString = GrannyGetLogMessageTypeString(Type);
66     char const* OriginString = GrannyGetLogMessageOriginString(Origin);
67    
68     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",
69     TypeString,
70     OriginString,
71     Message);
72    
73     VSDebugWriterW VSDebugWriter;
74    
75     VSDebugWriter
76     << "\n\n\tGranny2 API Logger: Logging Granny2 Message ->"
77     << "\n\t\tMessage Log Type: " << TypeString
78     << "\n\t\tMessage Log Origin: " << OriginString
79     << "\n\t\tMessage: " << Message;
80     }
81    
82     void GrannyAPILogger::LogMessage(const char* Message)
83     {
84     //printf("\n\tGranny2 API Logger: Logging Application Message ->\n\t\tMessage: %s",Message);
85     printf("\n\t%s",Message);
86    
87     VSDebugWriterW VSDebugWriter;
88    
89     VSDebugWriter << "\n\t" << Message;
90     /*<< "\n\tGranny2 API Logger: Application Message ->"
91     << "\n\t\tMessage: " << Message;*/
92     }
93     void GrannyAPILogger::LogDebugMessageOnly(const char* Message)
94     {
95     VSDebugWriterW VSDebugWriter;
96     VSDebugWriter << Message;
97     }

  ViewVC Help
Powered by ViewVC 1.1.22