Skip to content

Log Module

The log module provides logging functions for Lua scripts, allowing messages to be recorded with different severity levels. This module is useful for debugging, monitoring, and auditing scripts in production.

Key features:

  • 5 log levels: debug, info, warn, error

  • Identification by execution context

  • Automatic formatting of Lua values

  • Support for multiple arguments with tab-separated output

Sets an identifier for logs generated by the current script.

  • identificador (string): Unique identifier for the execution context
  • nil: The function does not return a value
  • The identifier is stored internally and persists for the duration of the script execution

  • All subsequent log messages will include this identifier

  • Useful to distinguish logs from different scripts or instances

-- Set identifier for a specific script
log.set_ident("monitoramento-cpu")
-- Now all logs will include "[monitoramento-cpu]"
log.info("Iniciando monitoramento")
-- Output: [lua] [monitoramento-cpu] Starting monitoring
-- In another script or context
log.set_ident("backup-automatico")
log.info("Iniciando backup")
-- Output: [lua] [backup-automatico] Starting backup

Logs DEBUG-level messages for detailed debugging information.

  • (multiple values): Values to be logged, separated by tabs
  • nil: The function does not return a value
-- Log variable values for debugging
local temperatura = 45.6
local uso_memoria = 78.3
log.debug("Variáveis de sistema:", "Temp:", temperatura, "Mem:", uso_memoria)
-- Output: [lua] [ident] System variables: Temp: 45.6 Mem: 78.3
-- Debug execution flow
log.debug("Entrando na função processar_dados")
log.debug("Parâmetros recebidos:", parametros)
log.debug("Configuração atual:", config)
-- Debug complex structures
local dados = {
usuario = "admin",
acao = "login",
timestamp = os.time()
}
log.debug("Dados da requisição:", dados)

Logs INFO-level messages for general execution information.

  • (multiple values): Values to be logged, separated by tabs
  • nil: The function does not return a value

Logs WARN-level messages for situations that require attention but are not errors.

  • (multiple values): Values to be logged, separated by tabs
  • nil: The function does not return a value

Logs ERROR-level messages for error conditions that require intervention.

  • (multiple values): Values to be logged, separated by tabs
  • nil: The function does not return a value