Simple logger
Jump to navigation
Jump to search
Game | non-mud specific |
By | Wyd |
Download | https://forums.mudlet.org/download/file.php?id=307&sid=ee16e5b03abb9d132a2a95bfd37f48fb |
Dependencies | Mudlet 4.17 |
Description
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.
Usage
Logger:Log(file, line_to_save, options_table)
- Simply appendsline_to_save
tofile.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 MUD until you callLogger: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 afterLogger:LogSection()
is called.
Logger:SearchLog(file, pattern)
- Searches throughfile.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 thekeepOpen
option (explained below). Thefile
parameter is optional, and if omitted, 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. Note: Dates in the order (dd/mm/yyyy). If you want to change this around, just modify thetime_format
variable inLogger:Log()
.
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 withLogger:Log()
, then it will check each time the function is called. WithLogger:LogSection()
, the file size 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 untilLogger:CloseLog(file)
is called. This allows a substantial performance gain when logging large amounts of data at once. If you use this, thenLogger: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})
See also: Mudlet Forums
Examples
I have included the following aliases to demonstrate its use:
log <file>
- Will callLogger:LogSection(<file>)
. If<type>
is "off", it will callLogger:StopLogging()
searchlog <file> <pattern>
- Will callLogger:SearchLog(<type>, <pattern>)
- A "slain" trigger for Achaea to demonstrate how to use the
Logger:Log()
function.