Search code examples
erlanggen-event

State in OTP event manager process (not handler!)


Can an OTP event manager process (e.g. a logger) have some state of its own (e.g. logging level) and filter/transform events based on it?


Solution

  • I also have a need to put some state into the gen_event itself, and my best idea at the moment is to use the process dictionary (get/put). Handlers are invoked in the context of the gen_event process, so the same process dictionary will be there for all handler calls.

    Yes, process dictionaries are evil, but in this case they seem less evil than alternatives (ets table, state server).