diff options
author | Steve Vinoski <[email protected]> | 2010-02-27 23:36:20 -0500 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-05-12 07:40:26 +0200 |
commit | 5ec0ade4105d5d72f318b657bff1a628881cbf9d (patch) | |
tree | 036de21bae7fe104f9efbe06574f67474c5d90fb /lib/stdlib/src/gen_fsm.erl | |
parent | dd908223cbf62adfeaefac982c4087cd35bb1805 (diff) | |
download | otp-5ec0ade4105d5d72f318b657bff1a628881cbf9d.tar.gz otp-5ec0ade4105d5d72f318b657bff1a628881cbf9d.tar.bz2 otp-5ec0ade4105d5d72f318b657bff1a628881cbf9d.zip |
Extend format_status for gen_server/gen_fsm termination error logging
When a gen_server or gen_fsm process terminates abnormally, sometimes
the text representation of the process state can occupy many lines of
the error log, depending on the definition of the state
term. Developers sometimes would like a way to trim out parts of the
state from the log if those parts don't contribute to documenting the
circumstances of the error, thereby helping to reduce the amount of
logged output.
Since the format_status callback can already format and specialize
gen_server and gen_fsm state for inclusion in the term returned from
sys:get_status, this patch extends format_status in a
backward-compatible way to also be able to specialize the state logged
for abnormal gen_server and gen_fsm termination, and includes new unit
tests to verify the new functionality.
This patch also eliminates the previous restriction that the status
returned by format_status must be a list. It can now be any term.
The documentation is extended to cover the new usage for
format_status, and it's been improved to recommend a form for the
normal case that allows the returned status to fit well with the rest
of the term returned by sys:get_status. The documentation is clear
that this form is only recommended, not required.
Diffstat (limited to 'lib/stdlib/src/gen_fsm.erl')
-rw-r--r-- | lib/stdlib/src/gen_fsm.erl | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/stdlib/src/gen_fsm.erl b/lib/stdlib/src/gen_fsm.erl index 9961646418..8d1b46d6ab 100644 --- a/lib/stdlib/src/gen_fsm.erl +++ b/lib/stdlib/src/gen_fsm.erl @@ -542,7 +542,18 @@ terminate(Reason, Name, Msg, Mod, StateName, StateData, Debug) -> {shutdown,_}=Shutdown -> exit(Shutdown); _ -> - error_info(Reason, Name, Msg, StateName, StateData, Debug), + FmtStateData = + case erlang:function_exported(Mod, format_status, 2) of + true -> + Args = [get(), StateData], + case catch Mod:format_status(terminate, Args) of + {'EXIT', _} -> StateData; + Else -> Else + end; + _ -> + StateData + end, + error_info(Reason,Name,Msg,StateName,FmtStateData,Debug), exit(Reason) end end. @@ -610,15 +621,17 @@ format_status(Opt, StatusData) -> end, Header = lists:concat(["Status for state machine ", NameTag]), Log = sys:get_debug(log, Debug, []), - Specfic = + DefaultStatus = [{data, [{"StateData", StateData}]}], + Specfic = case erlang:function_exported(Mod, format_status, 2) of true -> case catch Mod:format_status(Opt,[PDict,StateData]) of - {'EXIT', _} -> [{data, [{"StateData", StateData}]}]; - Else -> Else + {'EXIT', _} -> DefaultStatus; + StatusList when is_list(StatusList) -> StatusList; + Else -> [Else] end; _ -> - [{data, [{"StateData", StateData}]}] + DefaultStatus end, [{header, Header}, {data, [{"Status", SysState}, |