Skip to content

Loginator

Damian Monogue edited this page May 5, 2021 · 1 revision

Presenting... the LOGINATOR

Soon, you will be able to write all the logs in the TRI STATE AREA! muahahah

More seriously, someone pointed out on the Mudlet discord server that all the solutions for logging they could find were geared towards logging game output, but they could not find one geared towards logging script execution.

Since I had already solved some of the problems this would present for LoggingConsoles I figured I could throw something together.

That something... is the loginator.

Tell me more

While the loggers created by Loginator:new(options) are fairly highly configurable, it is designed to allow you to get up and running quickly if you are willing to accept some defaults.

Minimum setup

Designed to get you up and logging quickly, the bare minimum to create a new logger for writing to log files is

local loginator = require("MDK.loginator")
log = loginator:new()

And that's it. By default, this will write log files to getMudletHomeDir() .. "/log/Loginator/" and the files will be named YYYY-MM-DD-logname.html where YYYY is the year as 4 digits (2021), MM is the month in 2 digits (03, 10, etc), and DD is the day in 2 digits (01, 12, 28, etc).

Of course, it's not very useful if everyone uses that log file name, so I recommend providing at least a name

local loginator = require("MDK.loginator")
log = loginator:new({name = "SuperCoolScript"})

Which will save the file as YYYY-MM-DD-SuperCoolScript.html or 2021-05-04-SuperCoolScript.html at the time of writing.

Configurable

While it's designed to be easy to use with minimum setup/configuration, the ability to configure things is still there. The API Docs have a complete list of options and templating replacements.

Only logs what you're interested in

By setting the level of the logger, you are also telling it which log events should actually get written to file. The logger will only log events of an equal or higher severity to its level.

The levels from most to least severe are:

  • error
  • warn
  • info
  • debug

This means if your logger's level is "warn" then only error and warn messages will be written to disk. info and debug messages will quickly return from the function without writing the entry to disk. Then later if you need to get more information you can bump the level of the logger to info or debug, and the further information will be printed to disk.

Easy to use

Once you've created your logger, writing log entries is super easy.

-- assuming we created the logger as above
log:error("This will be an error level entry")
log:warn("And this will be a warn level entry")
log:info("And you were there, and you too info")
log:debug("I bet you already knew debug was coming huh?")

See? Barely an inconvenience. You can also write the above as

log:log("This will be an error level entry", "error")
log:log("And this will be a warn level entry", "warn")
-- etc

log:log("Extra bonus option. This will be whatever level the logger itself is. So the least severe thing that will actually be written to file.")
-- that would be 'warn' level in our default logger scenario.

I wanna read my logs, now what?

-- requests your OS to open the log file using an appropriate application
-- generally your web browser for html files and text editor for others
log:open()

-- opens the folder containing your log file. Useful for browsing through previous logs or if you're logging to more than one file via multiple loggers
log:openDir()

What's it look like?

Clone this wiki locally