New Improved HTML Logging Plugin

Posted by Sojik on Thu 16 Jun 2011 07:56 AM — 5 posts, 19,237 views.

USA #0
The default HTML color logging annoyed me a bit so I've redone it as a plugin.

Firstly, <font> is being phased out. They want you to use styles instead. I've made sure the html produced in the log is valid (valid XHTML 1.1 to be specific) because it's pretty easy.

Secondly, I thought it'd be better to just log the lines from the MUD directly to the log without splitting them. I do my wrapping in css.

I'll just post what I have and then explain it later when I have more time. Just know you need specific logging settings (uncheck logging commands, notes and output and uncheck color, raw and Write world name to log file). After you do that it's going to ask you if that's what you want to do and you have to say yes (each time you visit that tab).

Here's the preamble (if you know what you're doing you can mess with it):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>LOG:%N-%y/%m/%d %H:%M:%S (%P)</title>
<link rel="stylesheet" type="text/css" href="logstylesheet.css" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="log">


Postamble:
</div>
</body>
</html>


The different line preambles won't do anything with this plugin so you might as well blank those out.

Here's what I recommend for a log file name:
%L\%y.%m.%d.%H.%M.%S %N(%P).html


I'll post the XML in the next post and then what I'm using for CSS.
USA #1
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, June 16, 2011, 2:34 AM -->
<!-- MuClient version 4.73 -->

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

<muclient>
<plugin
   name="Improved_HTML_Logging"
   author="Scott Grossman"
   id="5d2f084bf4978af4f49db2b8"
   language="Lua"
   purpose="Improves HTML logging complete with external css support and fully valid XHML standards"
   date_written="2011-06-16 02:32:17"
   requires="4.73"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^.*$"
   name="output"
   regexp="y"
   script="WriteLogInHTML"
   send_to="12"
   sequence="1"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   name="command"
   script="WriteLogInHTML"
   match="^.*$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  <send>%0</send>
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
function GetAnsiNumber()
    local a = {}
    for i=1,8 do
        table.insert(a, GetNormalColour(i), i)
        table.insert(a, GetBoldColour(i), i+8)
        table.insert(a, 0, 0)
    end
    return a
end

function WriteLogInHTML(name, line, wildcards, styles)
    lino = [[<span title="]]..os.date("%A, %B %d, %Y %I:%M:%S%p")..[[" class="]]..name..[[">]]
    linc = [[</span>]]
    to = [[<span class="]]
    tc = [[">]]
    en = [[</span>]]
    nl = ""
    if name == "output" then
        for i=1,table.maxn(styles) do
            tec = GetAnsiNumber()[styles[i].textcolour]
            bac = GetAnsiNumber()[styles[i].backcolour]
            if tec == 8 then
                tec = ""
            else
                tec = "a"..tec
            end
            if bac == 0 then
                bac = ""
            else
                bac = " b"..bac
            end
            
            sty = ""
            s = styles[i].style

            if s == 1 or s == 3 or s == 5 or s == 7 or s == 9 or s == 11 or s == 13 or s == 15 then
                sty = sty.." b"
            end
            if s == 2 or s == 3 or s == 6 or s == 7 or s == 10 or s == 11 or s == 14 or s == 15 then
                sty = sty.." u"
            end
            if s == 4 or s == 5 or s == 6 or s == 7 or s == 12 or s == 13 or s == 14 or s == 15 then
                sty = sty.." i"
            end
            if s == 8 or s == 9 or s == 10 or s == 11 or s == 12 or s == 13 or s == 14 or s == 15 then
                sty = sty.." r"
            end
            
            tex = FixupHTML(styles[i].text)
            if tec == "" and bac == "" and sty == "" then
                nl = nl..tex
            else
                nl = nl..to..Trim(tec..bac..sty)..tc..tex..en
            end
        end
    elseif name == "command" then
        nl = FixupHTML(line)
    end
    WriteLog(lino..nl..linc)
end


]]>
</script>


</muclient>


[EDIT] Edited by Nick to escape forum codes.
Amended on Thu 16 Jun 2011 11:28 PM by Nick Gammon
USA #2
body {
    background-color:black;
    white-space:pre-wrap;
    font-family:monospace;
    width:80ch; /* Adjust this if your browser doesn't support 'ch' */
    font-size:10pt;
}
.command {
    color:rgb(50,205,50);
}
.output {
    color:rgb(192,192,192);
}
.a1 {
    color:rgb(105,105,105);
} /* ANSI colors 1-8 is dark and 9-16 is bright */
.a2 {
    color:rgb(128,0,0);
}
.a3 {
    color:rgb(0,128,0);
}
.a4 {
    color:rgb(128,128,0);
}
.a5 {
    color:rgb(0,0,128);
}
.a6 {
    color:rgb(128,0,0);
}
.a7 {
    color:rgb(0,128,128);
}
.a8 {
    color:rgb(192,192,192);
}
.a9 {
    color:rgb(128,128,128);
}
.a10 {
    color:rgb(255,0,0);
}
.a11 {
    color:rgb(0,255,0);
}
.a12 {
    color:rgb(255,255,0);
}
.a13 {
    color:rgb(0,0,255);
}
.a14 {
    color:rgb(255,0,255);
}
.a15 {
    color:rgb(0,255,255);
}
.a16 {
    color:rgb(255,255,255);
}
.b1 {
    background-color:rgb(105,105,105);
}
.b2 {
    background-color:rgb(128,0,0);
}
.b3 {
    background-color:rgb(0,128,0);
}
.b4 {
    background-color:rgb(128,128,0);
}
.b5 {
    background-color:rgb(0,0,128);
}
.b6 {
    background-color:rgb(128,0,0);
}
.b7 {
    background-color:rgb(0,128,128);
}
.b8 {
    background-color:rgb(192,192,192);
}
.b9 {
    background-color:rgb(128,128,128);
}
.b10 {
    background-color:rgb(255,0,0);
}
.b11 {
    background-color:rgb(0,255,0);
}
.b12 {
    background-color:rgb(255,255,0);
}
.b13 {
    background-color:rgb(0,0,255);
}
.b14 {
    background-color:rgb(255,0,255);
}
.b15 {
    background-color:rgb(0,255,255);
}
.b16 {
    background-color:rgb(255,255,255);
}
.u {
    text-decoration:underline;
}
.b {
    font-weight:bold;
}
.i {
    font-style:italic;
}
.r {
}


You have to name the css file logstylesheet.css and put it in your log directory. Why use an external css? You can edit colors and styles and automatically all of your logs will update.

One downside is if you need to copy from your html logs to post on your website. The classes I'm using won't color or style anything without the css file.
USA #3
I have an idea about an alias that'll throw an <a> (anchor) that we can link to into the log.

That way you can type in MUSHclient something like this:
lognote Beginning scene with Charlie


Then that'll log something like
<a id="note123">Beginning scene with Charlie</a>
and then maybe output that into a new HTML document with the links to all my anchors (i.e. file:///C:/Users/Scott/Dropbox/MUSHclient/logs/11.06.16.02.39.05%20R2A%28Ala%29.html#note123 etc.)

EDIT:

The reason I want to add this is to easily find scenes I want to see later. Eventually I'll be making my own local wiki with links to all of my character's scenes so this'll save me alot of time. I hate cleaning roleplay logs.

I used to use the DailyLog plugin and I don't think I will have to anymore with an alias like this.
Amended on Thu 16 Jun 2011 08:14 AM by Sojik
USA #4
I could add to the plugin something that'll automatically make the css file and set the logging settings for you but I'm not sure people want a plugin with os.executes in them.

Although, I may do it anyway because it'd be cool if the CSS file automatically updated itself if I change my color settings in MUSHclient to make them match.