Got Windows 7? Got Powershell? Rotate your logs without GLR

14 posts / 0 new
Last post
Offline
Layonara AdministratorDruidFolianiteGamemasterLucinditeWriting Team MemberXeenite
Joined: Oct 1 2004
Got Windows 7? Got Powershell? Rotate your logs without GLR

Yep, I got curious one day after finding out how easy it is to set up log rotation in Linux from within the shell script used to run NWN, so I wondered if I could do the same thing in Windows. Using Powershell, it turns out to be fairly simple.

  1. Open Notepad (or your text editor of choice)
  2. Copy and paste the following code into the new file:
    Quote:
    param ($nwn_path, $log_path, $dest_path, $log_pref)
    $DateStamp = get-date -uformat "%Y%m%d-%H%M%S"
    $final = $log_pref + "_$DateStamp.log"
    move-item "$nwn_path\$log_path\nwclientLog1.txt" "$nwn_path\$dest_path\$final"
  3. Save the file to your NWN folder as: nwn-log-rotator.ps1 Note: if using Notepad, make sure you change "Save as type:" drop-down to "All Files (*.*)" or else it will add a .txt extension to the end of the file name
  4. Create another new text file and paste the following into it:
    Quote:
    @echo off
    SET NWN_PATH="C:\NeverwinterNights\NWN" cd %NWN_PATH%
    start /w nwmain.exe +connect 
    173.198.229.123:5121 +password {player password}
    powershell %NWN_PATH%\nwn-log-rotator.ps1 %NWN_PATH% logs logs nwclientLog
  5. Save the file as Layonara-West.bat (or whatever you like, as long as it has a .bat extension)
  6. Close your text editor
  7. If desired, create desktop shortcuts to the .bat files for easy access.
Basically, that's it, except replace {player password} with the correct player password, given on character approval (also, remove the {}, in case there's any confusion). This will connect you to West and log you in automatically. Some of you may have NWN in a different folder than I do. If so, edit line 2 of the .bat file to point to the correct location. You can create a second file to connect directly to Central by using :5122 in the 4th line of the .bat file like this: start /w nwmain.exe +connect 173.198.229.123:5122 +password {player password} If you do not want to have separate direct-connect script for each server, just leave the connection parameters off: start /w nwmain.exe Regarding the last line in the .bat file, the Powershell script created in Step 2 takes four arguments. In order, they are:
  1. Folder path of NWN
  2. Folder path of the nwclientLog1.txt file (NWN's default log) relative to the NWN path
  3. Folder path where the rotated log file should be saved relative to the NWN path (this is usually the same as the path in #2)
  4. Prefix for the new log file
The Powershell script will rename/move the file to the destination folder with a name in the format: prefix_datecode.log, where prefix is from #4 and datecode follows the format of: {4-digit year}{Month}{Day}-{Hour}{Minute}{Second}. So the datecode for October 26th, 2012 at 3:27:15pm would be: 20121026-152715 Lines 2 and 3 of nwn-log-rotator.ps1 can be altered to change the naming format of the rotated log files. These scripts are presented as-is, and I don't guarantee they'll work right for your needs or at all...heh. Test them out for yourself before you rely on them. You've been warned. For convenience, I've attached the scripts above to this message. Un-RAR them into your NWN folder. You'll need to edit the Layonara-West.bat as described above to put the right player password into line 4 and, if necessary, adjust the NWN_PATH on line 2.

AttachmentSize
1018537_scripts.rar526 bytes
Thanks from:
Hellblazer's picture
Offline
Az'attanFolianiteMistitePrunillianToraniteVoraxian
Joined: May 14 2006

Do you know of a way to set it so it ask for text to save the file under? Like the old GLR used to do?


Aphel's picture
Offline
Angels Guild MemberFolianiteLucinditeToranite
Joined: Aug 15 2011

I am not sure if you can modify the batch like that. Quick&Dirty solution would be to create a batch for each of your characters, if that is what you had in mind.


Thanks from:
Offline
Layonara AdministratorDruidFolianiteGamemasterLucinditeWriting Team MemberXeenite
Joined: Oct 1 2004

Hellblazer wrote:
Do you know of a way to set it so it ask for text to save the file under? Like the old GLR used to do?


I'm sure Powershell can do that, but that's up to the reader/user to figure out. I'm just offering this as a basic option, not offering to support it or develop it further.


As Aphel suggested, you could make separate .bat files for each character you want to use, and set the destination folder and/or prefix to something different. That's essentially what I do for my GM logs to separate them from the player logs.


Thanks from:
Tanman's picture
Offline
AeridiniteDorandite
Joined: Jun 24 2006

This will work under Xp/Vista too if you have the powershell add on from Microsoft.


You can get the one for windows Xp here


For vista 32 bit link is here.


Vista 64 bit. Here.


Hth everyone that has older OS's and want to give this a shot. Nice work dorg!


Offline
Layonara AdministratorDruidFolianiteGamemasterLucinditeWriting Team MemberXeenite
Joined: Oct 1 2004

Thanks for doing the legwork on that Tanman.


Offline
Layonara AdministratorDruidFolianiteGamemasterLucinditeWriting Team MemberXeenite
Joined: Oct 1 2004

Also, it has come to my attention that the RAR file I attached had an incorrect script inside of it. I've corrected that and put the right file up for download. If anyone has downloaded the prior version, you'll need to download this again.


Sorry for the inconvenience.


Thanks from:
lonnarin's picture
Offline
GamemasterXeenitePrunillianDruidDoranditeToranite
Joined: Oct 8 2004

Thanks! That GM log rotater always irked me how buggy it was on my end. I'll definitely give this one a try. Gotta love coders like Dorg. We see a bad interface, they see a rubik's cube and solve it for fun. :D


Aphel's picture
Offline
Angels Guild MemberFolianiteLucinditeToranite
Joined: Aug 15 2011

Dorg, do you know of a way to get the name of the character selected out of NWN into that script?


Offline
Layonara AdministratorDruidFolianiteGamemasterLucinditeWriting Team MemberXeenite
Joined: Oct 1 2004

As far as I know, there aren't any ways to get that information from NWN nor is there any way to tell NWN which character to use. The best solution would be to prompt the user for a name/location/prefix before calling the Powershell script, but like I said, I'm not going to figure that out for anyone. I'm sure it's not hard, but I have other things to do.


Thanks from:
Tanman's picture
Offline
AeridiniteDorandite
Joined: Jun 24 2006

@Dorg @HB


Actually having looked at the line:


move-item "$nwn_path\$log_path\nwclientLog1.txt" "$nwn_path\$dest_path\$final"


you could try changing it to

""\$final"


ie for example if i wanted it for d:\NWN\logs

the last line might look like:


move-item "$nwn_path\$log_path\nwclientLog1.txt" "d:\nwn\logs\$final"


as it is just parsing paths. Give it a go and lets see how it turns out.


you could change this path to:


"


Offline
Angels Guild MemberPrunillian
Joined: Apr 12 2004

Ok I mostly got this to work, however, when I start with the standard nwn.exe in windows7 x64 it switches to basic color mode and it doesn't seem to be doing it with the batch file so NWN crashes everytime. Any thoughts on how to add something in there to switch the color mode?

Offline
Layonara AdministratorDruidFolianiteGamemasterLucinditeWriting Team MemberXeenite
Joined: Oct 1 2004

You can try finding your nwmain.exe program using Windows Explorer, right-clicking the file and selecting Properties.  Within the "Combatibility" tab there's a bunch of options.  The one marked "Disable desktop composition" should switch you to "Basic" mode on Win7 when you run nwmain.exe.

Thanks from:
cbnicholson's picture
Offline
Angels Guild MemberRofireinite
Joined: Mar 22 2006

Have this up and running.  Maybe now DB won't be so forgetful. :P  Thanks for bringing this to the players, Dorg!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Login or register to post comments