13
13
compliance with the License. You should have received a copy of the
14
14
Erlang Public License along with this software. If not, it can be
15
15
retrieved online at http://www.erlang.org/.
17
17
Software distributed under the License is distributed on an "AS IS"
18
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
19
the License for the specific language governing rights and limitations
24
24
<title>gen_server</title>
598
598
<p>The function should return the updated internal state.</p>
602
<name>Module:format_status(Opt, [PDict, State]) -> Status</name>
603
<fsummary>Optional function for providing a term describing the
604
current gen_server status.</fsummary>
606
<v>Opt = normal | terminate</v>
607
<v>PDict = [{Key, Value}]</v>
608
<v>State = term()</v>
609
<v>Status = term()</v>
613
<p>This callback is optional, so callback modules need not
614
export it. The gen_server module provides a default
615
implementation of this function that returns the callback
618
<p>This function is called by a gen_server process when:</p>
619
<list typed="bulleted">
621
of <seealso marker="sys#get_status/1">sys:get_status/1,2</seealso>
622
is invoked to get the gen_server status. <c>Opt</c> is set
623
to the atom <c>normal</c> for this case.</item>
624
<item>The gen_server terminates abnormally and logs an
625
error. <c>Opt</c> is set to the atom <c>terminate</c> for this
628
<p>This function is useful for customising the form and
629
appearance of the gen_server status for these cases. A
630
callback module wishing to customise
631
the <c>sys:get_status/1,2</c> return value as well as how
632
its status appears in termination error logs exports an
633
instance of <c>format_status/2</c> that returns a term
634
describing the current status of the gen_server.</p>
635
<p><c>PDict</c> is the current value of the gen_server's
636
process dictionary.</p>
637
<p><c>State</c> is the internal state of the gen_server.</p>
638
<p>The function should return <c>Status</c>, a term that
639
customises the details of the current state and status of
640
the gen_server. There are no restrictions on the
641
form <c>Status</c> can take, but for
642
the <c>sys:get_status/1,2</c> case (when <c>Opt</c>
643
is <c>normal</c>), the recommended form for
644
the <c>Status</c> value is <c>[{data, [{"State",
645
Term}]}]</c> where <c>Term</c> provides relevant details of
646
the gen_server state. Following this recommendation isn't
647
required, but doing so will make the callback module status
648
consistent with the rest of the <c>sys:get_status/1,2</c>
650
<p>One use for this function is to return compact alternative
651
state representations to avoid having large state terms
652
printed in logfiles.</p>