setLevel($loglevel); } /** * Set the log level. * * @param string $loglevel Log level to use */ public function setLevel($loglevel) { $this->loglevel = $loglevel; } /** * Set the log section. * * @param string $section Log section to use */ public function setSection($section) { $this->section = $section; } /** * Set the log caller. * * @param string $caller Log caller to use */ public function setCaller($caller) { $this->caller = $caller; } /** * Get the available log levels ordered by verbosity. * * @return array Log levels */ public function levels() { return array_flip(array('notice', 'fatal', 'info', 'warning', 'error', 'debug')); } /** * Log dispatcher. * * @param string $message Log message * @param string $level Log level */ public function log($message, $level = 'info') { // Get the available log levels. $levels = $this->levels(); // Log level checking. if (array_search($level, $levels) === FALSE) { $this->log("Invalid log level $level.", 'error'); return; } elseif ($levels[$level] > $levels[$this->loglevel]) { return; } // Dispatch. if ($this->section == 'action') { $this->caller->logMessage($message, $level); } else { $message = "[$level] $message"; if ($this->caller) { $this->caller->logSection('isisImporter', $message); } else { echo ("$message\n"); } } } /** * Progress notifier. * * @param int $entry Entry number * @param int $entries Total number of entries */ public function progress($entry, $entries) { $this->processed = $entry; $levels = $this->levels(); if ($this->section == 'action') { $this->caller->output .= "Saved item $entry\n"; } else { // Progress bar is just shown if loglevel is 'fatal' or lower. if ($levels['fatal'] >= $levels[$this->loglevel] && $this->caller) { $this->caller->progressBar($entry, $entries); } } return $this->processed; } }