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)
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 options
    template 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
Loginator:setColorForLevel(color, level)
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'
Loginator:getFullFilename()
Returns the full path and filename to the logfile
Loginator:error(msg)
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)
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)
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)
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)
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()
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()
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)
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
generated by LDoc 1.4.6 Last updated 2021-08-31 18:42:52