Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iFamishedX/HungerLib/llms.txt
Use this file to discover all available pages before exploring further.
MessageRouter is a structured logging and message-routing utility that routes messages to up to four destinations: the local terminal (origin), every server’s HungerBridge console (destination), every server’s in-game chat (broadcast), and a rotating date-stamped log file (filelog). The shorthand methods info(), warn(), and error() call origin and filelog only; call destination() and broadcast() directly when you need to reach those routes. Color and format transformations are applied per-destination using mapres map lists, so ANSI escape codes appear in the terminal, Minecraft color codes appear in chat, and plain stripped text is written to disk.
Log files are created automatically in the log_path directory and named {name}_YYYY-MM-DD.log.
Constructor
Identifier for this router. Used as the Python
logging.Logger name and as the prefix of log filenames: {name}_YYYY-MM-DD.log.List of server objects (typically
MinecraftServer instances) to route messages to. The router inspects each for a .bridge attribute (for destination) and a .sendBroadcast method (for broadcast), so plain GenericServer instances are silently skipped for those routes.Filesystem path to the directory where log files will be written. Created automatically with
mkdir(parents=True, exist_ok=True) if it does not exist.List of
mapres map objects applied when rendering text for the terminal (origin route). Defaults to ANSI color processing.Map list applied when rendering text for the HungerBridge console (
destination route).Map list applied when rendering text for in-game
tellraw broadcasts. Defaults to Minecraft color code processing.Map list applied before writing text to the log file. Defaults to stripping all color/format tokens so the file contains clean plain text.
Map list applied when rendering the timestamp and level prefix strings. Includes both ANSI color and time substitution.
Template string for the INFO-level prefix.
%hh%, %mm%, and %ss% are substituted with the current time by the maps.time map resolver.Template string for the WARN-level prefix.
Template string for the ERROR-level prefix.
Shorthand Methods
These are the primary methods for everyday use. Each one calls bothorigin (terminal print) and filelog (disk write) in a single call. They do not automatically call destination or broadcast — use the primitive routes directly for those.
info()
info_prefix and renders with origin_maps.
The message to log.
Additional map objects to append to the default map list for this call.
If provided, replaces the default map list entirely for this call.
Extra keyword arguments passed through to the
MapResolver for template variable substitution.str — the fully rendered terminal string (prefix + message with ANSI codes applied).
warn()
warn_prefix with a yellow color tag and renders with origin_maps.
The message to log.
Additional map objects to append to the default map list.
Replaces the default map list if provided.
Extra keyword arguments for template substitution.
str — the fully rendered terminal string.
error()
error_prefix with a red color tag and renders with origin_maps.
The message to log.
Additional map objects to append to the default map list.
Replaces the default map list if provided.
Extra keyword arguments for template substitution.
str — the fully rendered terminal string.
Primitive Routes
Use these when you need fine-grained control over which destinations receive a message, or when combining routes manually.origin()
stdout) with the appropriate level prefix and ANSI color codes.
The message body to render and print.
Log level controlling which prefix is prepended. Must be
"info", "warn", or "error".Extra map objects appended to the active map list for this call.
Replaces
origin_maps entirely if provided.Keyword arguments forwarded to the
MapResolver for template substitution.str — the full rendered string that was printed (prefix + message).
Raises InvalidLevelError if level is not "info", "warn", or "error".
destination()
Servers that has a .bridge attribute. Uses destination_maps for rendering.
The message to send.
Log level forwarded to
BridgeClient.log(message, level). Must be "info", "warn", or "error".Extra map objects appended to
destination_maps.Replaces
destination_maps entirely if provided.Keyword arguments forwarded to the
MapResolver.str — the rendered message string that was sent.
broadcast()
tellraw-based broadcast to every server in Servers that has a .sendBroadcast method. Uses broadcast_maps (Minecraft color codes by default) for rendering.
The message to broadcast in-game.
Extra map objects appended to
broadcast_maps.Replaces
broadcast_maps entirely if provided.Keyword arguments forwarded to the
MapResolver.str — the rendered message string that was broadcast.
filelog()
logging module. Uses file_maps (strip colors by default) so the file contains clean plain text. The file is named {name}_YYYY-MM-DD.log and located in log_path.
The message to write to the log file.
Logging level. Must be
"info", "warn", or "error". Maps to logger.info(), logger.warning(), and logger.error() respectively.Extra map objects appended to
file_maps.Replaces
file_maps entirely if provided.Keyword arguments forwarded to the
MapResolver.str — the stripped/rendered string that was written to the file.
Log File Format
Log files use the Pythonlogging formatter pattern:
./logs/bot_2024-07-15.log
log_path directory is created automatically if it does not exist.