Logging chat world sessions automatically

Posted by Hinotori on Thu 30 Aug 2007 02:58 AM — 5 posts, 21,214 views.

#0
Hi there, I'm a relatively new user, and I have a question regarding logging chats sent to closed worlds. I used the example that Nick Gammon graciously provided in the FAQ, and so far it has been working excellently. However, one thing that I would like to do is have each chat world log sessions automatically, appending received chats to their own log. Unfortunately, because each world is permanently disconnected, they never begin logging sessions automatically, even when automatic logging is set in their world settings.

This issue may seem minor, but given that I have 4-6 chat worlds open at the same time, it is a bit tedious to have to manually click the "log session" button for each one every time I start the client up.

If there's a way to force each window to log sessions automatically, I'd like to know. If not, then some help on how to append text received in the chat world to a text file would be appreciated. Thanks a lot!
Australia Forum Administrator #1
Save this plugin (between the lines) and install into each of your "logging" worlds. (In other words, copy and paste into a text file, save as AutoLogger.xml, and then use File -> Plugins to install it). That will open a log file as the world is opened (ie. when the client starts up, if you are automatically opening them).


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, August 31, 2007, 4:09 PM -->
<!-- MuClient version 4.15 -->

<!-- Plugin "AutoLogger" generated by Plugin Wizard -->

<muclient>
<plugin
   name="AutoLogger"
   author="Nick Gammon"
   id="46397de5db3216159f692896"
   language="Lua"
   purpose="Opens a log file when the world is opened"
   date_written="2007-08-31 16:03:25"
   requires="4.00"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginInstall ()
  OpenLog (GetInfo (58) ..   -- log files directory
           GetInfo (2) ..    -- world name
           os.date ("-%a-%b-%d-%Y-%H-%M.txt"), -- date and time
           true)  -- append to existing log of same name
end -- OnPluginInstall 

]]>
</script>

</muclient>



The work is done in OnPluginInstall - this simply opens the log file, using the log files directory (which you specify in the Global Preferences, appends the world name (so you can distinguish each one), and then appends the date and time. In my test I got this log file name:


C:\Program Files\MUSHclient\logs\SMAUG-Fri-Aug-31-16-13.txt


You simply have to change the os.date function call to modify the way the file name appears.
Amended on Thu 30 Aug 2007 06:17 AM by Nick Gammon
#2
Thanks Nick, especially for the fast reply.

This is close to what I want, but I noticed that it's now creating a new file for each session. Is it possible to modify the plug-in in such a way that it continuously appends sessions to the same log file (possibly with a header signifying the date and time of each session)?

I'm sorry for not yet being competent enough with the coding to deduce a solution by looking at the plug-in by itself.

Thanks again.
USA #3
Just change the script to something like this then.
function OnPluginInstall ()
  OpenLog (GetInfo (58) .. -- log files directory
           GetInfo (2),    -- world name
           true)  -- append to existing log of same name
  WriteLog ( os.date ("New Session at %a-%b-%d-%Y-%H-%M"), -- date and time )
end -- OnPluginInstall
Amended on Thu 30 Aug 2007 10:57 AM by Shaun Biggs
#4
I apologize that this response is a bit late.

Thank you, Shaun; that code was very helpful.

There was a slight problem with getting that code to work at first. But after looking at it for a bit, I figured out the problem: the comment "date and time" needed to be moved outside the parenthesis. I also figured out that GetInfo(51) appended logged text to the world's log file rather than sending them to the default directory. Here is the final revised section after working with it, in case anyone else wants to use it:


function OnPluginInstall ()
OpenLog (GetInfo (51), -- log files directory
true) -- append to existing log of same name
WriteLog ( os.date ("New Session at %a-%b-%d-%Y-%H-%M"))-- date and time
end -- OnPluginInstall



Thanks again you two.