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.
Options
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) If you want to change this around, just modify the time_format variable in Logger:Log()
Simple Logger
Simple Logger
Last edited by Wyd on Thu Jun 03, 2010 3:08 pm, edited 10 times in total.
Re: Simple Logger
What does type exactly mean?
Re: Simple Logger
Probably badly named..
Basically, its just the name of the file to log out to - minus the ".txt" on the end.
Basically, its just the name of the file to log out to - minus the ".txt" on the end.
Re: Simple Logger
Yes, quite . This is quite nice though, I think I'll finally setup perma-logging.
Re: Simple Logger
Updated the script to use "file" instead of "type" as the variable name, just for clarity
Re: Simple Logger
Loving this, btw. Great script.
Re: Simple Logger
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.
See the OP for both instructions and the script.
Re: Simple Logger
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
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
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.