Skip to content

AntumLuanti/mod-mod_logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mod Logger

Description

Mod for Luanti that wraps around the core logger. It adds extra functions & standardized logging output messages.

Usage

Adds a single global function add_mod_logger:

add_mod_logger()
add_mod_logger(name)
add_mod_logger(logger)
add_mod_logger(name, logger)
- name: (optional) Logger name that will prefix messages. If omitted, mod name will be used.
- logger: (optional) Table to which logging functions will be added. If omitted, a new table will be created
    & returned.
- return value: `logger` or new table with logging functions.

Once registered, the logger table will include the following functions:

Functions:

  • log(lvl, msg)
  • log(msg)
  • info(msg)
  • action(msg)
  • warn(msg)
  • error(msg)
  • debug(msg)

Parameters:

  • lvl: (optional) Logging level. Can be one of "error", "warn", "action", "info", or "debug". If its value is nil the standard message logging level will be used (same as log(msg)). "warning" is alias of "warn".
  • msg: Logging message text.

Settings

Note: Messages also abide by level of core Luanti logger. "info" & "debug" messages are output to the default core logger level.

Examples

Using as hard dependency:

my_mod = {}
add_mod_logger(my_mod)

Using as soft dependency:

my_mod = {
    -- only need to add functions that will be used
    log = function() end,
    info = function() end,
    action = function() end,
    warn = function() end,
    error = function() end,
    debug = function() end
}
if core.global_exists("add_mod_logger") then
    add_mod_logger(my_mod)
end

Calling logging functions:

-- outputs "[<mod_name>] Hello my_mod!" to Luanti logging console
-- same as `my_mod.log("Hello my_mod!")` or `my_mod.log(nil, "Hello my_mod!)`
my_mod.info("Hello my_mod!")

-- outputs "DEBUG[<mod_name>] Hello my_mod!" to Luanti logging console
-- same as `my_mod.log("debug", "Hello my_mod!")`
my_mod.debug("Hello my_mod!")

Creating a local logger:

local my_logger = add_mod_logger()
my_logger.info("Hello my_mod!")

Links

TODO

About

Mod for Luanti that adds standardized mod logging functions.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages