diff options
Diffstat (limited to 'lib/sfIsisImporterLog.class.php')
-rw-r--r-- | lib/sfIsisImporterLog.class.php | 49 |
1 files changed, 33 insertions, 16 deletions
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; @@ -46,10 +41,30 @@ class sfIsisImporterLog */ 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. * * @param string $message Log message @@ -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); } } |