Automation scripts that manage multiple game servers need to communicate across several channels simultaneously: a human operator watching a terminal, players in-game who need countdown warnings, console logs persisted for later auditing, and per-server bridge logs that record operational events.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 handles all of this from a single object. One call to router.info(...) prints a timestamped, color-coded line to the terminal and appends a clean plain-text entry to a rotating daily log file. One call to router.broadcast(...) sends a Minecraft-formatted message to every server in your list. You stop managing formatters, file handles, and color-code pipelines individually and express intent instead.
Constructor
A short identifier for this router instance. Used as the Python
logging logger name and embedded in log filenames (e.g. automation_2024-06-01.log).A list of
GenericServer or MinecraftServer instances that destination and broadcast routing methods will iterate over. Servers without a bridge attribute are silently skipped by destination; servers without a sendBroadcast method are silently skipped by broadcast.Directory path where daily log files will be written. The directory is created automatically (including parent directories) if it does not exist. Files are named
{name}_YYYY-MM-DD.log and rotated daily at the file-system level — a new handler is initialized per run.The
mapres map list applied to message text when routing to the terminal via origin(). Defaults to ASCII ANSI color resolution so that <green> and similar tags are converted to terminal escape codes.Map list applied to text sent to server bridge logs via
destination(). Defaults to ASCII colors so that color tags produce readable console output in the HungerBridge log.Map list applied to text sent to in-game broadcasts via
broadcast(). Defaults to Minecraft color resolution so that &e, &c, and other Minecraft color codes are preserved as-is and rendered by the game client.Map list applied to text written to log files via
filelog(). Defaults to color stripping so that log files contain clean plain text without embedded escape codes or Minecraft formatting characters.Map list applied when resolving prefix strings (
info_prefix, warn_prefix, error_prefix). Including maps.time allows %hh%, %mm%, and %ss% tokens to expand to the current wall-clock time.Prefix template prepended to all terminal output at the
info level. Supports <color> tags (resolved via prefix_maps) and %hh%:%mm%:%ss% time tokens.Prefix template for the
warn level. Defaults to yellow ANSI coloring.Prefix template for the
error level. Defaults to red ANSI coloring.Routing Methods
MessageRouter exposes two layers of methods. The primitive routes each send to exactly one destination and return the formatted string. The passthrough helpers (info, warn, error) combine origin and filelog into a single call for convenience.
info / warn / error
text to both the terminal (via origin) and the log file (via filelog) in one call. The level (info, warn, error) controls which prefix template is applied on the terminal and which Python log level is used in the file.
origin
stdout) only. No file is written. Use this for transient status lines you want visible in the console but not persisted.
destination
Servers that exposes a .bridge attribute by calling server.bridge.log(msg, level). This writes to the HungerBridge server log, not to the terminal or the file logger. Use it for per-server operational records.
broadcast
server.sendBroadcast(msg) on every server in Servers that supports it (i.e. MinecraftServer instances). Text is resolved through broadcast_maps (Minecraft color codes by default) so &e, &c, etc. are preserved and rendered in-game.
filelog
file_maps which strips color tags by default, keeping log files human-readable.
Color Maps and the <color> Syntax
MessageRouter uses the mapres library to resolve color tokens in message text. Different routes apply different map lists, so the same <green>text input produces different outputs depending on where it’s sent:
Terminal (origin)
Applies
maps.ascii_colors. <green> becomes the ANSI escape code \033[32m for terminal color output.In-game (broadcast)
Applies
maps.mc_colors. Minecraft & color codes are passed through unchanged for the game client to render.Log files (filelog)
Applies
maps.strip_colors. All color tags and codes are removed, leaving clean plain text in the .log file.%hh%, %mm%, and %ss% time tokens (resolved via maps.time) that expand to the current hour, minute, and second at the time the message is routed.
Example
Log files are written to
{log_path}/{name}_YYYY-MM-DD.log. A new log file is created each calendar day. If you run a long-lived process that crosses midnight, the file handler created at startup continues writing to the previous day’s file — restart the process or re-initialize MessageRouter to roll over to the new day’s file.Routing Reference
| Method | Terminal | Log File | Bridge Log | In-game Broadcast |
|---|---|---|---|---|
info | ✅ | ✅ | ❌ | ❌ |
warn | ✅ | ✅ | ❌ | ❌ |
error | ✅ | ✅ | ❌ | ❌ |
origin | ✅ | ❌ | ❌ | ❌ |
destination | ❌ | ❌ | ✅ | ❌ |
broadcast | ❌ | ❌ | ❌ | ✅ |
filelog | ❌ | ✅ | ❌ | ❌ |