(PECL mongo >= 1.3.0)
MongoLog::setCallback — Set a callback function to be called on events
This function will set a callback function to be called for MongoLog events instead of triggering warnings.
log_function
The function to be called on events.
The function should have the following prototype
$module
, int $level
, string $message
)module
level
message
Zwraca TRUE
w przypadku powodzenia, FALSE
w
przypadku błędu.
Przykład #1 MongoLog::setCallback() example
<?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: var_dump($level); return "UNKNOWN";
}
}
function callback($module, $level, $message)
{
printf("%s (%s): %s\n", module2string($module), level2string($level), $message);
}
MongoLog::setLevel(MongoLog::ALL);
MongoLog::setModule(MongoLog::ALL);
MongoLog::setCallback("callback");
new MongoClient();
?>
Powyższy przykład wyświetli coś podobnego do:
PARSE (INFO): Parsing standalone PARSE (INFO): - Found node: localhost:27017 PARSE (INFO): - Connection type: STANDALONE CON (INFO): mongo_get_read_write_connection: finding a STANDALONE connection CON (INFO): connection_create: creating new connection for localhost:27017 CON (INFO): get_server_flags: start CON (FINE): send_packet: read from header: 36 CON (FINE): send_packet: data_size: 70 CON (FINE): get_server_flags: setting maxBsonObjectSize to 16777216 CON (FINE): is_ping: pinging localhost:27017;X;7472 CON (FINE): send_packet: read from header: 36 CON (FINE): send_packet: data_size: 17 CON (WARN): is_ping: last pinged at 1349906451; time: 0ms
This function is only availalble with PHP 5.3.0 and later.