Page 1 of 3

Simple Logger

Posted: Sun May 02, 2010 8:20 am
by Wyd
Hi all,

The Simple logger is a basic logging system for Mudlet, that allows you to log text out to a file. The difference between this logger and the inbuild mudlet one, is that the Simple Logger allows you to log out only certain lines (For example, "You have slain <blah>."), or split your log files up into files of a certain size.

The Simple Logger is currently under constant development (and so, is not really so simple anymore!), so feel free to post comments and suggestions.

Currently, it has the following functionality:

Logger:Log(file, line_to_save, options_table) - Simple appends line_to_save to "file.txt". See the "options" section below to see the currently valid options

Logger:LogSection(file, options_table) - The logger will append every line that comes from the MID until you call Logger:StopLogging(). Not, this will only output stuff directly from the MUD, and not show echo's or such. See the "options" section below to see the currently valid options.

When you log a section, the logged output will be put between [[[START OF SECTION]]] and [[[END OF SECTION]]] to make sections easier to find.

Logger:StopLogging() - Stops logging after Logger:LogSection() is called.

Logger:SearchLog(file, pattern) - Searches through "file.txt" for the given pattern, and output matched lines. This uses rex_pcre to search, so the pattern can be regular expression.

Logger:CloseLog(file) - To be used with the "keepOpen" option (explained below). The "file" parameter is optional, and if ommited, then the Logger will close all open log files.


There are currently three recognized options:

"timestamp" - When included in the options table, the Logger will prefix each logged line with a time stamp

split = <number> - This tells the logger to ensure that the log file gets no larger then <number> kilobytes. If the log file gets larger then the given number, the logger will backup the old file.txt, and create a new one. If this option is used with Logger:Log(), then it will check each time the function is called. With Logger:LogSection(), the filesize is checked when logging first begins, and every 10 minutes after that, for performance reasons.

"keepOpen" - This option tells the Logger to not close the handle to the log file, and to keep it open until Logger:CloseLog(file) is called. This allows a substantial performance gain when logging large amounts of data at once. If you use this, then Logger:CloseLog() should be called when you close the connection to your MUD, to ensure that the Logger closes all open logs.

Note: LogSection uses "keepOpen" by default, and closes the log when the logging is stopped. This means you'll need to ensure that Logger:StopLogging() is called at some point.

Two examples of using the option table would be

Logger:Log("kills", { "timestamp"})
Logger:LogSection("arena", {split = 5000})

Examples of use

I have included the following aliases to demonstrate its use:
"log <file>" - Will call Logger:LogSection(<file>). If <type> is "off", it will call Logger:StopLogging()
"searchlog <file> <pattern> - Will call Logger:SearchLog(<type>, <pattern>)

And a "slain" trigger for Achaea to demonstrate how to use the Logger:Log() function.

One final note: I'm Australian, which means I put my dates in the correct order (dd/mm/yyyy) :P If you want to change this around, just modify the time_format variable in Logger:Log()
Using the &quot;SearchLog&quot; function (via the searchlog alias)
Using the "SearchLog" function (via the searchlog alias)
screenshot.JPG (59.47 KiB) Viewed 12232 times

Simple Logger Script
(8.66 KiB) Downloaded 1559 times

Re: Simple Logger

Posted: Sun May 02, 2010 3:43 pm
by Vadi
What does type exactly mean?

Re: Simple Logger

Posted: Sun May 02, 2010 4:45 pm
by Wyd
Probably badly named..

Basically, its just the name of the file to log out to - minus the ".txt" on the end.

Re: Simple Logger

Posted: Sun May 02, 2010 5:36 pm
by Vadi
Yes, quite :P. This is quite nice though, I think I'll finally setup perma-logging.

Re: Simple Logger

Posted: Mon May 03, 2010 9:59 am
by Wyd
Updated the script to use "file" instead of "type" as the variable name, just for clarity

Re: Simple Logger

Posted: Wed May 26, 2010 10:25 pm
by Vadi
Loving this, btw. Great script.

Re: Simple Logger

Posted: Sun May 30, 2010 4:02 pm
by Wyd
Updated the logger to allow for a "split" option, to ensure that log files are kept to a manageable size.

See the OP for both instructions and the script.

Re: Simple Logger

Posted: Tue Jun 01, 2010 3:33 pm
by Vadi
The new change works quite great, I've had it rotate logs in the middle of a spar without me noticing a thing.

Re: Simple Logger

Posted: Thu Jun 03, 2010 3:44 am
by Wyd
Vadi wrote:The new change works quite great, I've had it rotate logs in the middle of a spar without me noticing a thing.

Good to hear..I've noticed a couple of small bugs with it, that I'll fix in the next day or two (including some syntax bugs from when I changed the variable "type" to "file"

Re: Simple Logger

Posted: Thu Jun 03, 2010 5:54 am
by Wyd
Released Version 0.3! Logger now has a keepOpen option, allowing for better performance when logging out sections, or doing a big batch of Logger:Log() calls.