php-doc-en/reference/mongo/mongolog/setcallback.xml

203 lines
7.1 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongolog.setcallback" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoLog::setCallback</refname>
<refpurpose>Sets a callback function to be invoked for events</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>MongoLog::setCallback</methodname>
<methodparam><type>callable</type><parameter>log_function</parameter></methodparam>
</methodsynopsis>
<para>
This function will set a callback function to be invoked for events in lieu
of emitting of PHP notice.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>log_function</parameter></term>
<listitem>
<para>
The callback function to be invoked on events. It should have the following prototype:
</para>
<para>
<methodsynopsis>
<methodname><replaceable>log_function</replaceable></methodname>
<methodparam><type>int</type><parameter>module</parameter></methodparam>
<methodparam><type>int</type><parameter>level</parameter></methodparam>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
</methodsynopsis>
<variablelist>
<varlistentry>
<term><parameter>module</parameter></term>
<listitem>
<simpara>
One of the <link linkend="mongolog.constants.module">MongoLog
module constants</link>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>level</parameter></term>
<listitem>
<simpara>
One of the <link linkend="mongolog.constants.level">MongoLog
level constants</link>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>message</parameter></term>
<listitem>
<simpara>
The log message itself.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="mongolog.setcallback.example.basic">
<title><methodname>MongoLog::setCallback</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
function module2string($module)
{
switch ($module) {
case MongoLog::RS: return "REPLSET";
case MongoLog::CON: return "CON";
case MongoLog::IO: return "IO";
case MongoLog::SERVER: return "SERVER";
case MongoLog::PARSE: return "PARSE";
default: return "UNKNOWN";
}
}
function level2string($level)
{
switch ($level) {
case MongoLog::WARNING: return "WARN";
case MongoLog::INFO: return "INFO";
case MongoLog::FINE: return "FINE";
default: return "UNKNOWN";
}
}
function callback($module, $level, $message)
{
echo date("Y-m-d H:i:s - ");
printf("%s (%s): %s\n", module2string($module), level2string($level), $message);
}
MongoLog::setLevel(MongoLog::ALL);
MongoLog::setModule(MongoLog::ALL);
// We specify the function name here, but any callable (e.g. anonymous function) will work
MongoLog::setCallback("callback");
new MongoClient();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
2013-07-09 09:41:42 - PARSE (INFO): Parsing localhost:27017
2013-07-09 09:41:42 - PARSE (INFO): - Found node: localhost:27017
2013-07-09 09:41:42 - PARSE (INFO): - Connection type: STANDALONE
2013-07-09 09:41:42 - CON (INFO): mongo_get_read_write_connection: finding a STANDALONE connection
2013-07-09 09:41:42 - CON (INFO): connection_create: creating new connection for localhost:27017
2013-07-09 09:41:42 - CON (INFO): stream_connect: Not establishing SSL for localhost:27017
2013-07-09 09:41:42 - CON (INFO): get_server_flags: start
2013-07-09 09:41:42 - CON (FINE): send_packet: read from header: 36
2013-07-09 09:41:42 - CON (FINE): send_packet: data_size: 95
2013-07-09 09:41:42 - CON (FINE): get_server_flags: setting maxBsonObjectSize to 16777216
2013-07-09 09:41:42 - CON (FINE): get_server_flags: setting maxMessageSizeBytes to 48000000
2013-07-09 09:41:42 - CON (INFO): is_ping: pinging localhost:27017;-;.;1543
2013-07-09 09:41:42 - CON (FINE): send_packet: read from header: 36
2013-07-09 09:41:42 - CON (FINE): send_packet: data_size: 17
2013-07-09 09:41:42 - CON (INFO): is_ping: last pinged at 1373359302; time: 0ms
2013-07-09 09:41:42 - REPLSET (FINE): finding candidate servers
2013-07-09 09:41:42 - REPLSET (FINE): - all servers
2013-07-09 09:41:42 - REPLSET (FINE): filter_connections: adding connections:
2013-07-09 09:41:42 - REPLSET (FINE): - connection: type: STANDALONE, socket: 42, ping: 0, hash: localhost:27017;-;.;1543
2013-07-09 09:41:42 - REPLSET (FINE): filter_connections: done
2013-07-09 09:41:42 - REPLSET (FINE): limiting by seeded/discovered servers
2013-07-09 09:41:42 - REPLSET (FINE): - connection: type: STANDALONE, socket: 42, ping: 0, hash: localhost:27017;-;.;1543
2013-07-09 09:41:42 - REPLSET (FINE): limiting by seeded/discovered servers: done
2013-07-09 09:41:42 - REPLSET (FINE): limiting by credentials
2013-07-09 09:41:42 - REPLSET (FINE): - connection: type: STANDALONE, socket: 42, ping: 0, hash: localhost:27017;-;.;1543
2013-07-09 09:41:42 - REPLSET (FINE): limiting by credentials: done
2013-07-09 09:41:42 - REPLSET (FINE): sorting servers by priority and ping time
2013-07-09 09:41:42 - REPLSET (FINE): - connection: type: STANDALONE, socket: 42, ping: 0, hash: localhost:27017;-;.;1543
2013-07-09 09:41:42 - REPLSET (FINE): sorting servers: done
2013-07-09 09:41:42 - REPLSET (FINE): selecting near servers
2013-07-09 09:41:42 - REPLSET (FINE): selecting near servers: nearest is 0ms
2013-07-09 09:41:42 - REPLSET (FINE): - connection: type: STANDALONE, socket: 42, ping: 0, hash: localhost:27017;-;.;1543
2013-07-09 09:41:42 - REPLSET (FINE): selecting near server: done
2013-07-09 09:41:42 - REPLSET (INFO): pick server: random element 0
2013-07-09 09:41:42 - REPLSET (INFO): - connection: type: STANDALONE, socket: 42, ping: 0, hash: localhost:27017;-;.;1543
]]>
</screen>
</example>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<caution>
<para>
This function is only available with PHP 5.3.0 and later.
</para>
</caution>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->