A few things about logs

Posted by Zalethon on Sun 05 Nov 2006 03:49 PM — 3 posts, 13,836 views.

USA #0
I like to log all my games I play, and it can get kind of tedious having to enter all the information again and again in the logging section.. The first thing I'd like to suggest would be an addition to the logging section in global preferences, allowing you to set a default. Also it might be nice to have it prompt you if the folder it attempts to write in (in this case it was %N for the name of the game) doesn't exist, and allows you the option of having it created. Another suggestion really concerns scripting, there's a function to write to the log file, but perhaps there could be a function for writing to a separate log file? This could be used for things like logging IC and OOC in different logs.
Australia Forum Administrator #1
Quote:

... it can get kind of tedious having to enter all the
information again and again in the logging section ...


This is where plugins can be handy. A small plugin that sets things like "log_line_preamble_input" when you open your world, would do the trick. Simply install the plugin and your logs are fixed up! In fact, in global preferences you can make global plugins, so you can automatically have this plugin installed for each new world.

An example plugin would be:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, November 06, 2006, 8:08 AM -->
<!-- MuClient version 3.82 -->

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

<muclient>
<plugin
   name="LogFileFixup"
   author="Nick Gammon"
   id="e5e25c8f3f4eedbd9a32e5b2"
   language="Lua"
   purpose="Changes logging preambles, etc."
   date_written="2006-11-06 08:05:10"
   requires="3.52"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[
function OnPluginInstall ()
  if GetAlphaOption ("log_line_preamble_input") == "" then
    SetAlphaOption ("log_line_preamble_input", "mypreamble> ")
  end 
end -- OnPluginInstall

]]>
</script>


</muclient>


In this plugin I am changing the preamble to "mypreamble> " if it is currently empty. You could change other things, such as:


log_file_postamble
log_file_preamble
log_line_postamble_input
log_line_postamble_notes
log_line_postamble_output
log_line_preamble_input
log_line_preamble_notes
log_line_preamble_output


Quote:

Also it might be nice to have it prompt you if the folder it attempts to write in ... doesn't exist


You could also do this in the plugin. Some code like this could do it:


if ChangeDir ("\\mylogdirectory") == 0 then
  os.execute ("mkdir \\mylogdirectory")
  Note ("Creating directory \\mylogdirectory")
end -- directory not existing


This attempts to change to the log directory, and if that fails, it must not exist, so it uses os.execute to make it. You would need to trust your plugin in the Lua sandbox or the attempt to use os.execute will fail.

Quote:

Another suggestion really concerns scripting, there's a function to write to the log file, but perhaps there could be a function for writing to a separate log file?


You can script any number of log files, by simply making a trigger to catch the appropriate lines (eg. "IIC: *") and then call a script that simply writes to a file (using Lua io functions, for example). Then you simply make sure that your plugin opens the file when the world is connected (OnPluginConnect) and closed when the world is disconnected (OnPluginDisconnect).

So really, one plugin (like the one I presented earlier, but with a few additions) could handle all of that.
USA #2
K.. Thank you for the suggestions