diff options
author | Erlang/OTP <[email protected]> | 2010-05-21 07:32:18 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-05-21 07:32:18 +0000 |
commit | 56664e5bcde1a3147814bedfa94767c9465c90e3 (patch) | |
tree | fa76f08e8a106bdf00a97e359c1d46064f1bb2bb /lib/stdlib/src/gen_server.erl | |
parent | 641a0c6bbcff9b573d2f2ebadc13443be522cf35 (diff) | |
parent | 6281020ef3ac85afbfbe811de662ae5e1f19901d (diff) | |
download | otp-56664e5bcde1a3147814bedfa94767c9465c90e3.tar.gz otp-56664e5bcde1a3147814bedfa94767c9465c90e3.tar.bz2 otp-56664e5bcde1a3147814bedfa94767c9465c90e3.zip |
Merge branch 'sv/format_status_error_info' into dev
* sv/format_status_error_info:
Add support for the format_status callback to gen_event
Extend format_status for gen_server/gen_fsm termination error logging
OTP-8630 sv/format_status_error_info
When a gen_server, gen_fsm process, or gen_event 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. A
mechanism to trim out parts of the state from the log has been added (using
a format_status/2 callback). See the documentation.
Diffstat (limited to 'lib/stdlib/src/gen_server.erl')
-rw-r--r-- | lib/stdlib/src/gen_server.erl | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl index 1c9e5270b6..dc8e7ecd16 100644 --- a/lib/stdlib/src/gen_server.erl +++ b/lib/stdlib/src/gen_server.erl @@ -705,7 +705,18 @@ terminate(Reason, Name, Msg, Mod, State, Debug) -> {shutdown,_}=Shutdown -> exit(Shutdown); _ -> - error_info(Reason, Name, Msg, State, Debug), + FmtState = + case erlang:function_exported(Mod, format_status, 2) of + true -> + Args = [get(), State], + case catch Mod:format_status(terminate, Args) of + {'EXIT', _} -> State; + Else -> Else + end; + _ -> + State + end, + error_info(Reason, Name, Msg, FmtState, Debug), exit(Reason) end end. @@ -836,15 +847,17 @@ format_status(Opt, StatusData) -> end, Header = lists:concat(["Status for generic server ", NameTag]), Log = sys:get_debug(log, Debug, []), - Specfic = + DefaultStatus = [{data, [{"State", State}]}], + Specfic = case erlang:function_exported(Mod, format_status, 2) of true -> case catch Mod:format_status(Opt, [PDict, State]) of - {'EXIT', _} -> [{data, [{"State", State}]}]; - Else -> Else + {'EXIT', _} -> DefaultStatus; + StatusList when is_list(StatusList) -> StatusList; + Else -> [Else] end; _ -> - [{data, [{"State", State}]}] + DefaultStatus end, [{header, Header}, {data, [{"Status", SysState}, |