MongoLog
在线手册:中文  英文

MongoLog::setCallback

(PECL mongo >= 1.3.0)

MongoLog::setCallbackSet a callback function to be called on events

说明

public static void MongoLog::setCallback ( callable $log_function )

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

log_function ( int $module , int $level , string $message )
module
One of the MongoLog module constants.
level
One of the MongoLog level constants.
message
The log message itself.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #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();
?>

以上例程的输出类似于:

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

注释

Caution

This function is only availalble with PHP 5.3.0 and later.


MongoLog
在线手册:中文  英文
易百教程