Skip to content

LoggerPro — Runtime/Category

CategoryManager.cs — registration, enabled state, and the name-to-index map behind both.

Category view presets live in the editor-only Category/ folder at the package root. This one is in the runtime assembly because game code registers categories too.


The index map

Categories are addressed by name and stored in a list, so the manager keeps a name-to-index map. Indices rather than object references, because the list can be edited by hand in the JSON and a held reference would go stale silently.

TryGetIndex rebuilds the map whenever it looks stale. That is why the read path takes the lock as well as the write path — two threads merely reading an enabled state could be clearing and refilling the same dictionary at once, which either throws or hands back another category's entry, quietly applying one category's filter to another's logs.

Resolving the config

The manager can be built against a fixed LoggerProConfig or against an ILoggerConfigProvider. The default setup passes the provider, and the difference is not academic: "Reload From Disk" drops the store's config and builds a new one, and a manager holding the old instance went on showing the pre-reload category list while every toggle and every newly registered category was written to an object nothing would save. The button looked like it did nothing and quietly cost the session's category changes.

When the resolved config is a different instance from the one the map was built for, the map is rebuilt.

Registration

EnsureRegistered is on the hot path — it runs for every log call — so the already-registered case is a single dictionary lookup with no asset access.

Registration is automatic and permanent, and the list is committed with the project, so past 200 categories it warns once that the names are probably being generated from data rather than written by hand. It warns rather than refuses: an unregistered category is one the console cannot match a filter to, so refusing to register would answer "too many category names" by hiding the logs.

Remove is the way back out, and is deliberately not on ICategoryManager — that interface is documented as an injectable service, so adding a member would break every third-party implementation. LoggerPro.RemoveCategory reaches it, and the console offers it on a right-click.