ModuleLog: each module's own log, labelled with its id, reached as context.log(), PackWorld.log() and FeatureRegistry.log()

This commit is contained in:
piexel committed 2026-10-10 14:00:38 +02:00
1 parent d7de5939d7
commit e0ffe04a0d
26 files changed
+625 -27

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
package com.volmit;
/** The log of one module. The host labels every line with the module's id, such as {@code [iris:decorant]}, and writes it
* to its own log, so a module never needs a logging library of its own and its lines are easy to find. Each module has
* its own: reach it as {@code context.log()} in stage bodies and generators
* ({@link com.volmit.generation.InvocationContext#log}), as {@link com.volmit.world.PackWorld#log} in services and
* lifecycle hooks, and as {@link FeatureRegistry#log} while the module registers.
*
* <p>Safe to use from any thread. A message is plain text, not a format string.
*/
public interface ModuleLog {
/** Detail for people debugging the module. The host writes it only when its debug setting is on, so building the
* message costs time even when nobody reads it: guard a message that is expensive to build, or leave it out.
*/
void debug(String message);
/** Something worth telling the server owner once in a while, such as what the module did at startup. */
void info(String message);
/** Something is wrong or unusual, but the module carries on. */
void warn(String message);
/** Warns the first time {@code key} is used on this log and writes {@code message} at {@link #debug} level every
* time after, for a condition worth stating once that is met per block, per sample or per chunk. Keys belong to the
* module: two modules can use the same key and each warns once. The key space must be bounded, so never put a
* coordinate in it; the host stops claiming new keys beyond a few hundred and then only debugs.
*/
void warnOnce(String key, String message);
/** Logs {@code message} as an error and reports {@code cause} the way the host reports its own failures, such as
* to its error tracker. Use it for a failure the module caught but cannot recover from. A null {@code cause}
* only logs the message.
*/
void error(String message, Throwable cause);
}