Lumesh Log Module

wiki libs

Lumesh Shell Log Module Documentation


Module Path

log.


Log Level Constants

Constant Path Value Description
log.level.none 0 Disable all logs
log.level.error 1 Critical error (red output)
log.level.warn 2 Warning (yellow output)
log.level.info 3 Information (green output, default level)
log.level.debug 4 Debug (blue output)
log.level.trace 5 Trace (purple output)

Log Control Functions

1. log.set_level

Set the global log level

  • Parameters:
    • level: integer (must be a log.level.* constant value)
  • Returns: none
  • Errors:
    • TypeError: Non-integer parameter
    • ArityError: Number of parameters ≠ 1

Example:

# Enable DEBUG and above levels
log.set_level log.level.debug

2. log.get_level

Get the current log level

  • Parameters: None
  • Returns: integer (current level value)

Example:

log.get_level()  ; => 4 (DEBUG)

3. log.disable

Disable all logs (equivalent to set_level 0)

  • Parameters: None
  • Returns: none

Example:

log.disable()

4. log.enabled?

Check if the specified level is enabled

  • Parameters:
    • level: integer (log level value)
  • Returns: Boolean (true/false)

Example:

# Check if INFO level is enabled
log.enabled log.level.info ; => true

Log Output Functions

All functions:

  • Support any number of parameters (automatically concatenated into a string)
  • Multi-line text automatically aligns prefixes
  • Skips output if below the current level

1. log.error

Output error log (red)

  • Parameters: Any type (automatically converted to string)
  • Returns: none

Example:

log.error "File not found:" "/data/config.yaml"
# Output: 🔴 [ERROR] File not found: /data/config.yaml

2. log.warn

Output warning log (yellow)

  • Parameters: Any type

Example:

log.warn "Deprecated API called at line" 42
# Output: 🟡 [WARN] Deprecated API called at line 42

3. log.info

Output information log (green)

  • Parameters: Any type

Example:

log.info "Server started on port" 8080
# Output: 🟢 [INFO] Server started on port 8080

4. log.debug

Output debug log (blue)

  • Parameters: Any type

Example:

log.debug "Received JSON:" "{ id: 5, status: \"ok\" }"
# Output: 🔵 [DEBUG] Received JSON: { id: 5, status: "ok" }

5. log.trace

Output trace log (purple)

  • Parameters: Any type

Example:

log.trace "Function entry:" "calculate_score()"
# Output: 🟣 [TRACE] Function entry: calculate_score()

6. log.echo

Raw output (no prefix/color/level filtering)

  • Parameters: Any type
  • Features:
    • Does not add log prefix
    • Not controlled by log level

Example:

log.echo "Raw output" (math.sum 1 2)  ; # => Raw output 3

Multi-line Output Specification

log.info "Multiline message:\nLine1\nLine2"

Output Effect:

[INFO] Multiline message:
Line1
Line2

Rules:

  1. The first line displays a colored label
  2. Subsequent lines are indented to align with the label length
  3. Automatically appends a newline character at the end

Note: Color effects should be viewed in an ANSI-supported terminal.