The World of Layonara  Forums

Author Topic: Got Windows 7? Got Powershell? Rotate your logs without GLR  (Read 1550 times)

orth

Got Windows 7? Got Powershell? Rotate your logs without GLR
« 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]
  • 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"
  • 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 
    173.198.229.123:5121 +password {player password}
    powershell %NWN_PATH%\\nwn-log-rotator.ps1 %NWN_PATH% logs logs nwclientLog
  • 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.
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]
  • 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
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.
 
The following users thanked this post: swoop, Chazzler, Xiaobeibi, Aphel

Hellblazer

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #1 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?

Aphel

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #2 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.
 

Dorganath

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #3 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.
 

Tanman

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #4 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

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!
 

Dorganath

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #5 on: October 27, 2012, 10:47:25 am »
Thanks for doing the legwork on that Tanman.
 

Dorganath

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #6 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.
 

lonnarin

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #7 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
 

Aphel

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #8 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?
 

Dorganath

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #9 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.
 

Tanman

Re: Got Windows 7? Got Powershell? Rotate your logs without GLR
« Reply #10 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:

"
 

swoop

Ok I mostly got this to work,
« Reply #11 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?

 

Dorganath

You can try finding your
« Reply #12 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.

 

cbnicholson

Have this up and running. 
« Reply #13 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!

"Give a man a mask and he will show you his true face." 

Oscar Wilde