From 6281020ef3ac85afbfbe811de662ae5e1f19901d Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Sun, 28 Feb 2010 00:13:10 -0500 Subject: Add support for the format_status callback to gen_event The gen_server and gen_fsm behaviors support the format_status callback to allow developers to specialize how callback module state appears within the return value of sys:get_status and within logged output resulting from abnormal process termination. This patch adds similar support to gen_event. Event handlers that export a format_status/2 function, which is an optional callback, and are registered with an event manager will now have their format_status callbacks invoked when sys:get_status is called on the event manager. The term returned from format_status for this case replaces the default handler state in the sys:get_status return value. This patch also extends gen_event to call an event handler's format_status function (if it exports one) should the handler terminate abnormally. The term returned from format_status is logged in place of the handler's state. This is intended to allow developers to control how much output is logged in the case of abnormal termination. The documentation is appropriately extended and new unit tests are added to cover the new gen_event format_status functionality. --- lib/stdlib/doc/src/gen_event.xml | 58 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'lib/stdlib/doc/src/gen_event.xml') diff --git a/lib/stdlib/doc/src/gen_event.xml b/lib/stdlib/doc/src/gen_event.xml index df09294de6..4f4931eed0 100644 --- a/lib/stdlib/doc/src/gen_event.xml +++ b/lib/stdlib/doc/src/gen_event.xml @@ -630,12 +630,66 @@ gen_event:stop -----> Module:terminate/2

The function should return the updated internal state.

+ + Module:format_status(Opt, [PDict, State]) -> Status + Optional function for providing a term describing the + current event handler state. + + Opt = normal | terminate + PDict = [{Key, Value}] + State = term() + Status = term() + + + +

This callback is optional, so event handler modules need + not export it. If a handler does not export this function, + the gen_event module uses the handler state directly for + the purposes described below.

+
+

This function is called by a gen_event process when:

+ + One + of sys:get_status/1,2 + is invoked to get the gen_event status. Opt is set + to the atom normal for this case. + The event handler terminates abnormally and gen_event + logs an error. Opt is set to the + atom terminate for this case. + +

This function is useful for customising the form and + appearance of the event handler state for these cases. An + event handler callback module wishing to customise + the sys:get_status/1,2 return value as well as how + its state appears in termination error logs exports an + instance of format_status/2 that returns a term + describing the current state of the event handler.

+

PDict is the current value of the gen_event's + process dictionary.

+

State is the internal state of the event + handler.

+

The function should return Status, a term that + customises the details of the current state of the event + handler. Any term is allowed for Status. The + gen_event module uses Status as follows:

+ + When sys:get_status/1,2 is called, gen_event + ensures that its return value contains Status in + place of the event handler's actual state term. + When an event handler terminates abnormally, gen_event + logs Status in place of the event handler's actual + state term. + +

One use for this function is to return compact alternative + state representations to avoid having large state terms + printed in logfiles.

+
+
SEE ALSO -

supervisor(3), +

supervisor(3), sys(3)

- -- cgit v1.2.3