Class Loginator
Loginator creates an object which allows you to log things to file at various severity levels, with the ability to only log items above a specific severity to file.
Info:
- Copyright: 2021 Damian Monogue
- License: MIT, see LICENSE.lua
- Author: Damian Monogue
Methods
loginator:new(options) | Creates a new Loginator object |
loginator:setColorForLevel(color, level) | Set the color to associate with a logging level post-creation |
loginator:getFullFilename() | Returns the full path and filename to the logfile |
loginator:error(msg) | Write an error level message to the logfile. |
loginator:warn(msg) | Write a warn level message to the logfile. |
loginator:info(msg) | Write an info level message to the logfile. |
loginator:debug(msg) | Write a debug level message to the logfile. |
loginator:log(msg, level) | Write a message to the log file and optionally specify the level |
loginator:open() | Uses openUrl() to request your OS open the logfile in the appropriate application. |
loginator:openDir() | Uses openUrl() to request your OS open the directory the logfile resides in. |
loginator:getPath(filename) | Returns the path to the log file (directory in which the file resides) as a string |
Methods
- loginator:new(options) line 214
-
Creates a new Loginator object
Parameters:
- options
table
table of options for the logger
option name description default format What format to log in? "h" for html, "a" for ansi, anything else for plaintext. "h" name What is the name of the logger? Will replace |n in templates logname level What level should the logger operate at? This will control what level the log function defaults to, as well as what logs will actually be written
Only items of an equal or higher severity to this will be written to the log file."info" bgColor What background color to use for html logs "black" fgColor What color to use for the main text in html logs "white" fontSize What font size to use in html logs 12 levelColors Table with the log level as the key, and the color which corresponds to it as the value { error = "red", warn = "DarkOrange", info = "ForestGreen", debug = "ansi_yellow" } fileNameTemplate A template which will be transformed into the full filename, with path. See template options below for replacements "|p/log/Loginator/|y-|M-|d-|n.|e" entryTemplate The template which controls the look of each log entry. See template options below for replacements "|y-|M-|d |h:|m:|s.|x [|c|l|r] |t"
Table of template optionstemplate code what it is replaced with example |y the year in 4 digits 2021 |p getMudletHomeDir() /home/demonnic/.config/mudlet/profiles/testprofile |M Month as 2 digits 05 |d day, as 2 digits 23 |h hour in 24hr time format, 2 digits 03 |m minute as 2 digits 42 |s seconds as 2 digits 34 |x milliseconds as 3 digits 194 |e Filename extension expected. "html" for html format, "log" for everything else html |l The logging level of the entry, in ALLCAPS WARN |c The color which corresponds with the logging level. Set via the levelColors table in the options. Example not included. |r Reset back to standard color. Used to close |c. Example not included |n The name of the logger, set via the options when you have Loginator create it. CoolPackageLog
Returns:
-
newly created logger object
- options
table
table of options for the logger
- loginator:setColorForLevel(color, level) line 288
-
Set the color to associate with a logging level post-creation
Parameters:
- color The color to set for the level, as a string. Can be any valid color string for cecho, decho, or hecho.
- level The level to set the color for. Must be one of 'error', 'warn', 'info', or 'debug'
Returns:
-
true if the color is updated, or nil+error if it could not be updated for some reason.
- loginator:getFullFilename() line 332
- Returns the full path and filename to the logfile
- loginator:error(msg) line 339
-
Write an error level message to the logfile. Error level messages are always written.
Parameters:
- msg the message to log
Returns:
-
true if msg written, nil+error if error
- loginator:warn(msg) line 349
-
Write a warn level message to the logfile.
Msg is only written if the logger level is <= warn
From most to least severe the levels are:
error > warn > info > debug
Parameters:
- msg the message to log
Returns:
-
true if msg written, false if skipped due to level, nil+error if error
- loginator:info(msg) line 359
-
Write an info level message to the logfile.
Msg is only written if the logger level is <= info
From most to least severe the levels are:
error > warn > info > debug
Parameters:
- msg the message to log
Returns:
-
true if msg written, false if skipped due to level, nil+error if error
- loginator:debug(msg) line 369
-
Write a debug level message to the logfile.
Msg is only written if the logger level is debug
From most to least severe the levels are:
error > warn > info > debug
Parameters:
- msg the message to log
Returns:
-
true if msg written, false if skipped due to level, nil+error if error
- loginator:log(msg, level) line 377
-
Write a message to the log file and optionally specify the level
Parameters:
- msg the message to log
- level the level to log the message at. Defaults to the level of the logger itself if not provided.
Returns:
-
true if msg written, false if skipped due to level, nil+error if error
- loginator:open() line 409
- Uses openUrl() to request your OS open the logfile in the appropriate application. Usually your web browser for html and text editor for all others.
- loginator:openDir() line 414
- Uses openUrl() to request your OS open the directory the logfile resides in. This allows for easier browsing if you have more than one file.
- loginator:getPath(filename) line 420
-
Returns the path to the log file (directory in which the file resides) as a string
Parameters:
- filename optional filename to return the path of. If not supplied, with use the logger's current filename