logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Changing the Log Files which get rotated?

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Nov 04, 2009 14:10    Post subject: Changing the Log Files which get rotated? Reply with quote

I read a previous post which explained a method of adding additional log file names which get rotated on restarts of nwnx.

However, the code must have been different back in 2007 than what it is now, cause I cannot for the life of me find the code this previous post referred to

eg
strcpy(oldDirName, baseDirName);
strcpy(oldDirName,"nwnx_odbc.txt");

etc

Instead of finding this in the nwnserver.cpp file, I find this

Code:

void RotateLogs()
{
   char tmpNo[3] = {0};
   char baseDirName[256] = {0};
   char oldDirName[256] = {0};
   char newDirName[256] = {0};
   char tmpFileName[256] = {0};

   if (strlen(GetLogDir()) == 0)
      return;

   GetCurrentDirectory(256, baseDirName);
   strcat(baseDirName, "\\");
   strcat(baseDirName, GetLogDir());
   strcat(baseDirName, "\\");

    time_t curtime;
    tm now;
    time(&curtime);
    now = *localtime(&curtime);
    sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);

    // Create directory from filename
    CreateDirectory(newDirName, NULL);

    // Move previous log files to new directory
    sprintf(tmpFileName, "%s*.txt", baseDirName);
    WIN32_FIND_DATA wfd;
    HANDLE h_find = FindFirstFile(tmpFileName, &wfd);
    while (h_find != INVALID_HANDLE_VALUE)
   {
      sprintf(oldDirName, "%s%s", baseDirName, wfd.cFileName);
      sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d\\%s", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, wfd.cFileName);
      MoveFile(oldDirName, newDirName);
      if (!FindNextFile(h_find, &wfd))
     {
        FindClose(h_find);
        h_find = INVALID_HANDLE_VALUE;
      }
   }
}


I understand bits and pieces of this code, my main knowledge lyes in C# not C++ could someone please point out where I need to change, to get nwnx_chat.txt rotated as well?


The way this code looks,
Quote:

HANDLE h_find = FindFirstFile(tmpFileName, &wfd);
while (h_find != INVALID_HANDLE_VALUE)
{


It looks like its a simple loop which loops through each file in a directory, but obviously, its not doing that for me, since it is still only rotating 4 log files.

I thought to myself, maybe INVALID_HANDLE_VALUE listed a list of things to class as invalid log files to rotate or something, but it seems to just be a classic constant or something.

Anyone know where I need to edit?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Nov 04, 2009 17:01    Post subject: Seriously lol Reply with quote

Seriously, C++ is hurting my head. Lol


Quote:

void RotateLogs()
{
char tmpNo[3] = {0};
char baseDirName[256] = {0};
char oldDirName[256] = {0};
char newDirName[256] = {0};
char tmpFileName[256] = {0};

if (strlen(GetLogDir()) == 0)
return;

GetCurrentDirectory(256, baseDirName);
strcat(baseDirName, "\\");
strcat(baseDirName, GetLogDir());
strcat(baseDirName, "\\");

time_t curtime;
tm now;
time(&curtime);
now = *localtime(&curtime);
sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);

// Create directory from filename
CreateDirectory(newDirName, NULL);

// Move previous log files to new directory
sprintf(tmpFileName, "%s*.txt", baseDirName);
WIN32_FIND_DATA wfd;
HANDLE h_find = FindFirstFile(tmpFileName, &wfd);
while (h_find != INVALID_HANDLE_VALUE)
{
sprintf(oldDirName, "%s%s", baseDirName, wfd.cFileName);
sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d\\%s", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, wfd.cFileName);
MoveFile(oldDirName, newDirName);
if (!FindNextFile(h_find, &wfd))
{
FindClose(h_find);
h_find = INVALID_HANDLE_VALUE;
}
}
}



Ok, I am slowly starting to understand this code..

Quote:

char tmpNo[3] = {0};
char baseDirName[256] = {0};
char oldDirName[256] = {0};
char newDirName[256] = {0};
char tmpFileName[256] = {0};


Defining Variables/ Objects - I believe that this is creating arrays or tables, im gonna assume arrays.

Quote:

GetCurrentDirectory(256, baseDirName);
strcat(baseDirName, "\\");
strcat(baseDirName, GetLogDir());
strcat(baseDirName, "\\");

Gets the log directory path.


Quote:

time_t curtime;
tm now;
time(&curtime);
now = *localtime(&curtime);
sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);

This is where I am totally lost - I have no idea what part of the log file generation requires the acquisition of the year, month, hour etc. As far as I can tell, this is writing the date details into the directory name or something.
<somestring>datedetails etc.

Quote:


// Create directory from filename
CreateDirectory(newDirName, NULL);

Creates the actual directory if not existing?


Now the complicated stuff

Quote:

// Move previous log files to new directory
sprintf(tmpFileName, "%s*.txt", baseDirName);
WIN32_FIND_DATA wfd;
HANDLE h_find = FindFirstFile(tmpFileName, &wfd);

From what I can tell, sprintf is writing tmpFileName onto the extension .txt, in the basedirectory.
Then a new object called wfd is being made, which is being populated with the found data from the WIN32_FINE_DATA method.

Handle h_find is created, which basically holds the reference to the file which is found via wfd - i think.

Quote:

while (h_find != INVALID_HANDLE_VALUE)
{
sprintf(oldDirName, "%s%s", baseDirName, wfd.cFileName);
sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d\\%s", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, wfd.cFileName);
MoveFile(oldDirName, newDirName);
if (!FindNextFile(h_find, &wfd))
{
FindClose(h_find);
h_find = INVALID_HANDLE_VALUE;
}
}
}



While h_find still has a file to work with, we append the filename (wfd.cFileName) onto the baseDirName to get the filepath to that object on our disk drive.

It then appends some strings, decimals etc ("%s%d-%d-%d--%d-%d-%d\\%s",) onto the newDirName or something, to get the new directory path...

Then it magically moves the file....

Then it does a getNextFile, and continues ....

my question - Why isnt this moving the nwnx_chat.log file?

It is in the base Directory, like the rest... so why aint it rotating?

Im checking the other methods, its occuring to me, that perhaps the onCreate method moves the logs to the logs.0\1\ folder, and so on, and the reason the logs arent rotating, is because they arent being transfered into the 1 folder, and therefore not getting put into the rotation cycle.....

ooooh... thats probably it...
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Nov 04, 2009 17:19    Post subject: strange Reply with quote

Strange... my musings have lead me to discover that while the odbc log does infact get created in base directory, and in the 1 directory, it however does not update in both locations in real time.

The 1 directory, only receives the 'payload' of the final directory, once the server has closed down.....

My investigations urge me to delve deeper into the dark world that is c++. Lol
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Nov 04, 2009 17:37    Post subject: Reply with quote

rotating happens on the start of the nwnx application...

Quote:

void StartAndInject(char* cl)
{
ZeroMemory(&si,sizeof(si));
si.cb = sizeof(si);

RotateLogs();
StartServerProcess(cl, &si, &pi);
}




Meh.... I give up...


Someone please compile a version of nwnx2 that does log file rotation for at least the nwnx_chat.txt file pls?


I cant even compile the blasted app, it keeps giving me an error on
error c2733: second C linkage of overloaded function 'CreateRemoteThreadEx' not allowed - in madCHook.h -line 216, col 1.
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Wed Nov 04, 2009 17:53    Post subject: Reply with quote

I'm behind this block of code; before I changed it, it just moved logs.8 to logs.9, logs.7 to logs.8, etc., then hardcoded filenames into logs.1. Now it *should* move all log files into a timestamped directory name. It's strange that it doesn't.

BTW, your interpretation of the code is somewhat off. I'll step through it with you if you want. Smile
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Nov 04, 2009 18:11    Post subject: ah Reply with quote

Ah...
Well... my current version that I am using is labelled
(Executable)
File Version 2,6,1,1 - dated 19/5/2009


This version creates the file structure as follows

nwn\logs.0\1\
nwn\logs.0\2\
nwn\logs.0\3\
nwn\logs.0\4\
nwn\logs.0\5\
nwn\logs.0\6\
nwn\logs.0\7\
nwn\logs.0\8\
nwn\logs.0\9\


etc


If possible, could you run a compile of your most recent code, and post me an executable? I cant seem to get Visual Studio - Beta 2 or Visual Studio Express 2008 to build the nwnx app.


It would be great to actually have chat logs from previous server instances.

Also - nwnx is a fab thing an all, but I was wondering, would nwnx be possible to make in c#? Or was it decided to be done in c++ because it was only possible to do in c++?
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Wed Nov 04, 2009 18:22    Post subject: Reply with quote

http://mercuric.net/nwn/nwnx/ has it (that change was r39).

Possible in C#? Maybe. A huge headache to deal with native/.NET interop, especially at the level that NWNX is working? Definitely. Besides that, C# was just in its infancy when NWNX was started.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Nov 04, 2009 18:37    Post subject: Yay Reply with quote

Yeah Zeb, that seems to be working - now got a folder with the date/timestamp as its name.

So I take it this will allow me to keep log files indefinitly? Eg - it wont recycle the folders or overwrite logs.
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Wed Nov 04, 2009 19:25    Post subject: Reply with quote

Correct!
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group