The NWN Persistent World > Layonara Server

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

(1/3) > >>

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.[LIST=1] [*]Open Notepad (or your text editor of choice) [*]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"
--- End quote ---
[*]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 [*]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 +password {player password}
powershell %NWN_PATH%\\nwn-log-rotator.ps1 %NWN_PATH% logs logs nwclientLog
--- End quote ---
[*]Save the file as Layonara-West.bat (or whatever you like, as long as it has a .bat extension) [*]Close your text editor [*]If desired, create desktop shortcuts to the .bat files for easy access.[/LIST]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:
--- Code: ---start /w nwmain.exe +connect +password {player password}
--- End code ---
If you do not want to have separate direct-connect script for each server, just leave the connection parameters off:
--- Code: ---start /w nwmain.exe
--- End code ---
Regarding the last line in the .bat file, the Powershell script created in Step 2 takes four arguments. In order, they are:[LIST=1] [*]Folder path of NWN [*]Folder path of the nwclientLog1.txt file (NWN's default log) relative to the NWN path [*]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) [*]Prefix for the new log file[/LIST]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.

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 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.


--- Quote from: Hellblazer ---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?
--- End quote ---
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.

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!


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version