MongoLog
PHP Manual

MongoLog::setCallback

(PECL mongo >= 1.3.0)

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

Descrizione

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.

Elenco dei parametri

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.

Valori restituiti

Restituisce TRUE in caso di successo, FALSE in caso di fallimento.

Esempi

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

Il precedente esempio visualizzerĂ  qualcosa simile a:

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

Note

Attenzione

This function is only availalble with PHP 5.3.0 and later.


MongoLog
PHP Manual