Class Explainer
-
- All Implemented Interfaces:
public final class ExplainerA diagnostic recorder for a single search run.
An instance collects why a search reached its result: which recipes became candidates, which check rejected a recipe, and which predicate failed. Pass one to io.github.sakaki_aruka.customcrafter.search.Search.search (or its async / partial counterparts) and read the collected lines back with getLogs or getStringList.
Lines are recorded only when their level is not more verbose than verbosity: Loglevel.WARN alone keeps errors, Loglevel.INFO adds what happened, and Loglevel.DEBUG adds the concrete values behind each decision.
This class is safe to share across threads. io.github.sakaki_aruka.customcrafter.search.Search.asyncSearch evaluates candidate recipes in parallel and writes to one instance from every worker, so lines from different recipes interleave. Every line carries the recipe it belongs to, and the recorded order is a faithful trace of the actual execution order.
- Since:
5.3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classExplainer.LogA single recorded line.
public enumExplainer.LoglevelSeverity of a recorded line.
Loglevel.verbosity grows as the level gets more detailed, so a level is kept when its Loglevel.verbosity is less than or equal to the Explainer.verbosity threshold. Note this is the inverse of the "higher is more severe" convention used by most logging frameworks.
-
Field Summary
Fields Modifier and Type Field Description private final Explainer.Loglevelverbosityprivate final Stringname
-
Constructor Summary
Constructors Constructor Description Explainer(Explainer.Loglevel verbosity, String name)Explainer(Explainer.Loglevel verbosity)Explainer()
-
Method Summary
Modifier and Type Method Description final Explainer.LoglevelgetVerbosity()final StringgetName()final UnitwriteLog(Explainer.Loglevel level, String line)Records a line when level is not more verbose than verbosity. final List<Explainer.Log>getLogs()Returns every recorded line in the order it was written. final List<String>getStringList(Explainer.Loglevel targetLevels)Returns recorded lines rendered as "[LEVEL] message", keeping only targetLevels.StringtoString()-
-
Constructor Detail
-
Explainer
Explainer(Explainer.Loglevel verbosity, String name)
- Parameters:
verbosity- The most verbose level to keep.name- Label for this instance.
-
Explainer
Explainer(Explainer.Loglevel verbosity)
- Parameters:
verbosity- The most verbose level to keep.
-
Explainer
Explainer()
-
-
Method Detail
-
getVerbosity
final Explainer.Loglevel getVerbosity()
-
writeLog
final Unit writeLog(Explainer.Loglevel level, String line)
Records a line when level is not more verbose than verbosity.
Callable from a io.github.sakaki_aruka.customcrafter.matter.CMatterPredicate or a io.github.sakaki_aruka.customcrafter.recipe.CRecipePredicate through the explainer exposed on their context, so a predicate can record why it rejected an input.
- Parameters:
level- Level of this lineline- Message body.- Since:
5.3.0
-
getLogs
final List<Explainer.Log> getLogs()
Returns every recorded line in the order it was written.
- Returns:
List Recorded lines
- Since:
5.3.0
-
getStringList
final List<String> getStringList(Explainer.Loglevel targetLevels)
Returns recorded lines rendered as
"[LEVEL] message", keeping only targetLevels.Unlike the verbosity threshold applied when writing, this filters by exact level, so
getStringList(Loglevel.WARN)returns warnings alone. Passing no level returns everything.- Parameters:
targetLevels- Levels to keep.- Returns:
List Rendered lines
- Since:
5.3.0
-
-
-
-