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 +++++++++++++++++++++++++------------ lib/sfIsisImporterManager.class.php | 14 +++++------ 2 files changed, 40 insertions(+), 23 deletions(-) (limited to 'lib') 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); } } diff --git a/lib/sfIsisImporterManager.class.php b/lib/sfIsisImporterManager.class.php index 7d5d9b3..d261f67 100644 --- a/lib/sfIsisImporterManager.class.php +++ b/lib/sfIsisImporterManager.class.php @@ -41,11 +41,11 @@ class sfIsisImporterManager extends IsisConnector /** * Progress notifier dispatcher. * - * @param int $n Row number + * @param int $entry Entry number */ - public function progress($n) + public function progress($entry) { - $this->processed = $this->logger->progress($n); + $this->processed = $this->logger->progress($entry, $this->entries); } /** @@ -104,8 +104,8 @@ class sfIsisImporterManager extends IsisConnector } } - $this->log("Finished mass import procedure."); - $this->log("Total entries processed: $this->processed."); + $this->log("Finished mass import procedure.", 'notice'); + $this->log("Total entries processed: $this->processed.", 'notice'); } /** @@ -133,7 +133,7 @@ class sfIsisImporterManager extends IsisConnector if ($importer) { // Determine base model and max entries. - $this->log('Starting mass import procedure for config '. $database .'.'); + $this->log('Starting mass import procedure for config '. $database .'.', 'notice'); $base_model = $importer->format['db']['base_model']; $this->entries = ($entries != NULL && $entries <= $importer->entries) ? $entries : $importer->entries; @@ -141,7 +141,7 @@ class sfIsisImporterManager extends IsisConnector for ($entry = 1; $entry <= $this->entries; $entry++) { $importer->addEntry($base_model, $entry); - $this->progress($entry); + $this->processed = $this->progress($entry); } } -- cgit v1.2.3