The World of Layonara

The NWN Persistent World => Layonara Server => Topic started by: orth on December 07, 2014, 05:12:47 pm

Title: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: orth on December 07, 2014, 05:12:47 pm
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] 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: [Select]
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:
Code: [Select]
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:[LIST=1] 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.
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Hellblazer on October 26, 2012, 07:28:48 pm
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?
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Aphel on October 26, 2012, 07:33:29 pm
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.
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Dorganath on October 26, 2012, 10:15:46 pm
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?
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.
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Tanman on October 27, 2012, 05:56:37 am
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 (http://www.microsoft.com/en-us/download/details.aspx?id=16818)

For vista 32 bit link is here (http://www.microsoft.com/en-us/download/details.aspx?id=9864).

Vista 64 bit. Here (http://www.microsoft.com/en-us/download/details.aspx?id=9239).

Hth everyone that has older OS's and want to give this a shot. Nice work dorg!
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Dorganath on October 27, 2012, 10:47:25 am
Thanks for doing the legwork on that Tanman.
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Dorganath on October 27, 2012, 10:49:48 am
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.
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: lonnarin on October 27, 2012, 12:39:18 pm
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
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Aphel on October 27, 2012, 12:51:41 pm
Dorg, do you know of a way to get the name of the character selected out of NWN into that script?
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Dorganath on October 27, 2012, 01:49:45 pm
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.
Title: Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
Post by: Tanman on January 03, 2013, 06:07:11 am
@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:

"
Title: Ok I mostly got this to work,
Post by: swoop on December 07, 2014, 10:38:06 pm

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?

Title: You can try finding your
Post by: Dorganath on December 08, 2014, 08:51:36 am

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.

Title: Have this up and running. 
Post by: cbnicholson on December 26, 2014, 09:18:40 am

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