HTML Logging of Commands & World.Send [& more blank lines]

Posted by Magnum on Fri 14 Jun 2002 09:40 AM — 10 posts, 29,653 views.

Canada #0
I think I've mentioned this before, but here I go again:

Do a World.Note in your script, and it logs fine, in the colour of the note. Cool.

Do a World.Send, and it doesn't log at all. World.WriteLog logs in the default colour for the HTML page (usually black). Also, regular commands you enter are not logged in the "echo_colour" you have configured.

Preferably, the following functionality could be coded directly into MUSHclient:

Log text sent via command box in "echo_colour".
Log text sent via World.Send in "echo_colour". *
* World.Send does not currently log at all.

I've tried to work around this, which has presented several problems:

Sub LogSend (SendString)
	Dim Preamble, Postamble
	Dim CommandColour
	World.Send SendString
	If World.GetOption("log_html") Then
		CommandColour = World.CustomColourText(World.GetOption("echo_colour"))
		Preamble = World.GetAlphaOption("log_line_preamble_input")
		Preamble = Preamble & "<font color='" & CommandColour & "'>"
		Postamble = World.GetAlphaOption("log_line_postamble_input")
		Postamble = "</font>" & Postamble
		World.WriteLog Preamble & World.FixupHTML(SendString) & Postamble
	Else
		World.WriteLog SendString
	End If
End Sub

Looks like it should work, but the colour is wrong, for some reason (though not the default black). I thought maybe the echo_colour started from 0, so I put a -1 before the second closing bracket on the relevant line. Different colour, but still wrong. Hmmm....

The Preamble and Postamble don't work as easily as I would like. Variables are not evaluated, so I end up with a literal %H:%M> in my logs, rather than the current hour and Minutes. I could rip the string apart and build a proper pre-amble, but that just seems so bothersome at the moment. I doubt I will.

Setting the font above is actually overkill in my case, since this is the setting I currently have for logging:

   log_line_postamble_input="&lt;/font&gt;"
   log_line_preamble_input="%H:%M&gt; &lt;font color=#FF8040&gt;"

I set the font colour directly in the pre-amble, because it's the only way to get text entered into the command box to be in the colour I want (short of triggering every line and sending it through this routine).

...So, currently I have the font lines in the script commented out, and rely on the font settings stored directly in the pre & post amble.

I was thinking of building a Plugin to do all of this automatically, so that I wouldn't have to manually adjust the settings for every world. Also, since some people find the setup too complex, it would be easy to just hand them a file to have it work... but I don't see how that is possible with the current implementation. (The font colour is hard-coded in the pre-amble, instead of pulling it from the settings). Alternatively, I might just try and build a default file with all my personal colour and logging options in one file, if that is possible.
Canada #1
Something else I noticed while playing around with this:

It appears blank lines are still being sent to the output and log file, although not like before.

If I send a single line via script, it will have a blank line afterwards.

If I send multiple lines via script, there will only be a blank line after the last line sent. (both in output window and logs).
Australia Forum Administrator #2
OK, I'll investigate all that. The %H should be converted, sounds like a bug.
Canada #3
I have a standalone plugin that I keep various script routines in, that I expect will be used by an assortment of other plugins. Unfortunately, it means all of my "plugin" releases will actually be two plugins: The main plugin, and a "Script Tools" plugin with common script routines in it.

I use Logsend instead of World.Send in all my scripts, and would like to do so in all my plugins, so it's important that I get the routine mentioned above working, and in a manner that is accomodating to anyone else using my plugins.

...So thanks for responding, and I look forward to getting this cleaned up. :)
Australia Forum Administrator #4
I don't see a big problem with releasing a second plugin that is used by all your other ones. That was what the ability to call routines in other plugins was done for.

However another approach would be to include the other routines rather than call them. The effect would be slightly different, you would have different copies, so any (local) variables would not be shared. However it means you don't need to rely upon the plugin actually being installed.

eg.

<include name="my_common_routines.xml" />
Australia Forum Administrator #5
OK, I see what is wrong here:


CommandColour = World.CustomColourText(World.GetOption("echo_colour"))


This will send (for instance):


<font color='255'>


This is not valid HTML. You need this:


<font color='red'>


To do this in the script you need one more call:


CommandColour = World.RGBColourToName (World.CustomColourText(World.GetOption("echo_colour")))


Then it will work. :)
Canada #6
Somewhere in another thread, I recommended this:

Take the internal code for "World.Note" logging, clone it and edit it, and use it for "World.Send" as well.

The World.Note logging works perfectly, logging in the proper colour, with the proper variable explansion for line pre-ambles, etc. If World.Send worked the same way, there would be no need for my subroutine.

Since it's unlikely many plugin writers will write their code to log World.Send functions, it puts the user in an uncomfortable position of having to modify the plugin to get the full logging they may expect. This really should be the job of MUSHclient, in my humble opinion. :)
Australia Forum Administrator #7
Quote:

Variables are not evaluated, so I end up with a literal %H:%M> in my logs, rather than the current hour and Minutes.


Seems to work for me - where did you have them? Line preamble, file preamble? Was HTML on or not?
Canada #8
Same subroutine posted up at the top. The %H:%M> is pulled from "log_line_preamble_input" in my world.xml file. (Which is where it is saved after I used the "Configure - Logging" Interface to set the appropriate field.)

In essence, the problem is that:

World.GetAlphaOption("log_line_preamble_input")

returns the literal string, not an evaluation of the variable markers within that string.

I'm sure I, or any other programmer could parse and evaluate the value returned from that function. Personally, I can't be bothered to do the work, as I still hold hope that you'll read my last message in this forum and follow that suggestion. :) (I'm still wishin you'd answer why it's not feasible). LOL.

Anyway, you said in an E-mail that you've added "World.LogSend". That should also resolve the problem.
Australia Forum Administrator #9
Ah yes, it does indeed return the literal value of that setting. Could be annoying if it didn't.