Log Rotater

Yes it says General which means just that.

Moderators: Dungeon Masters, Hala DM

Post Reply
User avatar
Zerub
DM
DM
Posts: 889
Joined: Mon Jan 25, 2010 2:13 am
Location: Missouri

Log Rotater

Post by Zerub » Fri Apr 05, 2013 10:23 pm

Just in case anyone is wanting a log rotater, here is one that I wrote quite a few years back.

It will name the file something like:

2007-10-31-13.40.15.csv

That way you can sort them by the date and time. The log file that is created is tab delimeted for easy opening in a spreadshee. That way you can sort it, delete things that you don't want easily and then re-sort it back in order with pertinent info.

You just need perl on your computer which is no big deal. You can just download it and run the install script. Perl is a line interpreter so it is not running all the time and only runs when it executes a script. Here is the script and a basic setup of what to do if anyone is looking for a rotator. (there are others out there also).
**************************************************************************************

Here is what you need to get a log rotator. First you will need to download and install Active Perl.

here

Then open up Notepad and paste these lines into it and save it to the desktop as nwn.bat or wherever you want to start NWN from.
C:\NeverwinterNights\nwn.exe
pause
c:\perl\bin\perl -w c:\nwn_log_rotate.pl
If your Neverwinternights is somewhere else then you may need to edit the first line to reflect that. I just always install it in the root of C under NeverwinterNights. Also, if you install Perl somewhere else you may need to change the c:\perl\bin\perl to wherever you installed it. i.e. c:\documents\perl\bin\perl If you install the 64 bit version, you would need to change C:\perl to C:\perl64


Open up another instance of notepad and paste these lines into it and save
it to the root of C:\ as nwn_log_rotate.pl

$log_dir = "C:\\NeverwinterNights\\logs\\";
$log_file = $log_dir."nwclientLog1\.txt";
($sec, $min, $hour, $day, $month, $year) = (localtime)[0,1,2,3,4,5];
$year=$year+1900; $month++;
if ($month < 10) { $month = "0".$month };
if ($day < 10) { $day = "0".$day };
$date_file =
$log_dir.$year."-".$month."-".$day."-".$hour.'.'.$min.'.'.$sec.'.csv';
$line_number = 1;
open output_file, ">$date_file";
open input_file, "$log_file";
while (<input_file>) {
chomp;
s/\[CHAT WINDOW TEXT\] //g;
m/^(\[[^]]*\])?([^:]*:)?(.*)$/;
print output_file "$line_number\t";
$line_number++;
if ($1) { print output_file "$1\t" };
if ($2) { print output_file "$2\t" };
if ($3) { print output_file "$3" };
print output_file "\n";
}
close input_file;
close output_file;
Again, you may need to change the first line if your NWN is in a different directory. Make sure to note the double \\ here. You must have two and not one between each directory. Not going to go into details why, if you use Perl then you know, if you don't there is no need to know, just do it. :)

Now you can click on the nwn.bat file that you created to run the program (you may need to right click the nwn.bat file and 'run as administrator'). It will keep a DOS box open during game play. Once you end your session, just hit 'ENTER' on the box and it will run the script which creates your log.

Post Reply