From 3a6f275518bc62d7fcf41cc52bae46160478c07a Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 30 Jul 2010 12:00:24 -0300 Subject: Logging fixes --- lib/sfIsisImporterLog.class.php | 49 +++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'lib/sfIsisImporterLog.class.php') diff --git a/lib/sfIsisImporterLog.class.php b/lib/sfIsisImporterLog.class.php index 34594a6..2dcd4a3 100644 --- a/lib/sfIsisImporterLog.class.php +++ b/lib/sfIsisImporterLog.class.php @@ -27,15 +27,10 @@ class sfIsisImporterLog * * @param string $loglevel Log level to use */ - public static function getInstance($loglevel = null) + public static function getInstance($loglevel = 'info') { if(self::$instance == null) { - self::$instance = new self; - } - - if ($loglevel != null) - { - self::$loglevel = $loglevel; + self::$instance = new self($loglevel); } return self::$instance; @@ -45,10 +40,30 @@ class sfIsisImporterLog * Constructor. */ private function __construct($loglevel = 'info') + { + $this->level($loglevel); + } + + /** + * Set the log level. + * + * @param string $loglevel Log level to use + */ + public function level($loglevel) { $this->loglevel = $loglevel; } + /** + * Get the available log levels ordered by verbosity. + * + * @return array Log levels + */ + public function levels() + { + return array_flip(array('notice', 'fatal', 'info', 'warn', 'error', 'debug')); + } + /** * Log dispatcher. * @@ -57,8 +72,8 @@ class sfIsisImporterLog */ public function log($message, $level = 'info') { - // Available log levels ordered by verbosity. - $levels = array_flip(array('fatal', 'info', 'warn', 'error', 'debug')); + // Get the available log levels. + $levels = $this->levels(); // Log level checking. if (array_search($level, $levels) === FALSE) @@ -85,22 +100,24 @@ class sfIsisImporterLog /** * Progress notifier. * - * @param int $n Row number + * @param int $entry Entry number + * @param int $entries Total number of entries */ - public function progress($n) + public function progress($entry, $entries) { - $this->processed = $n; + $this->processed = $entry; + $levels = $this->levels(); if ($this->section == 'action') { - $this->caller->output .= "Saved item $n\n"; + $this->caller->output .= "Saved item $entry\n"; } else { - // Progress bar is just shown if loglevel is 'fatal'. - if ($this->loglevel == 'fatal') + // Progress bar is just shown if loglevel is 'fatal' or lower. + if ($levels['fatal'] >= $levels[$this->loglevel]) { - $this->caller->progressBar($n, $this->entries); + $this->caller->progressBar($entry, $entries); } } -- cgit v1.2.3