DB\Mongo::log PHP Method

log() public method

Return MongoDB profiler results (or disable logging)
public log ( $flag = TRUE ) : string
$flag bool
return string
    function log($flag = TRUE)
    {
        if ($flag) {
            $cursor = $this->selectcollection('system.profile')->find();
            foreach (iterator_to_array($cursor) as $frame) {
                if (!preg_match('/\\.system\\..+$/', $frame['ns'])) {
                    $this->log .= date('r', $frame['ts']->sec) . ' (' . sprintf('%.1f', $frame['millis']) . 'ms) ' . $frame['ns'] . ' [' . $frame['op'] . '] ' . (empty($frame['query']) ? '' : json_encode($frame['query'])) . (empty($frame['command']) ? '' : json_encode($frame['command'])) . PHP_EOL;
                }
            }
        } else {
            $this->log = FALSE;
            $this->setprofilinglevel(-1);
        }
        return $this->log;
    }

Usage Example

Exemplo n.º 1
0
 function log()
 {
     $log = parent::log();
     return str_replace("\n", "<br>", $log);
 }