aboutsummaryrefslogtreecommitdiff
path: root/lib/sfIsisImporterLog.class.php
diff options
context:
space:
mode:
authorSilvio <s1lv10@uol.com.br>2010-07-30 10:51:29 -0300
committerSilvio <s1lv10@uol.com.br>2010-07-30 10:51:29 -0300
commite2e83df93a77ff7d7597384a26d17a0aef2eb232 (patch)
treecbb95816a65cdf0dce9b7f76654004212a2da8fb /lib/sfIsisImporterLog.class.php
parent94d00beeab1f520159ddee0c81f3c57a8accb394 (diff)
downloadsf_isis_importer_plugin-e2e83df93a77ff7d7597384a26d17a0aef2eb232.tar.gz
sf_isis_importer_plugin-e2e83df93a77ff7d7597384a26d17a0aef2eb232.tar.bz2
Adding missing class files
Diffstat (limited to 'lib/sfIsisImporterLog.class.php')
-rw-r--r--lib/sfIsisImporterLog.class.php109
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/sfIsisImporterLog.class.php b/lib/sfIsisImporterLog.class.php
new file mode 100644
index 0000000..34594a6
--- /dev/null
+++ b/lib/sfIsisImporterLog.class.php
@@ -0,0 +1,109 @@
+<?php
+
+/**
+ * Logger.
+ *
+ * @todo $this->caller, $this->section
+ */
+class sfIsisImporterLog
+{
+ /**
+ * @var object $instance The singleton instance.
+ */
+ private static $instance = null;
+
+ /**
+ * @var object $instance Default loglevel.
+ */
+ public static $loglevel;
+
+ /**
+ * @var int $processed Number of processed entries.
+ */
+ var $processed = 0;
+
+ /**
+ * Get the singleton instance.
+ *
+ * @param string $loglevel Log level to use
+ */
+ public static function getInstance($loglevel = null)
+ {
+ if(self::$instance == null) {
+ self::$instance = new self;
+ }
+
+ if ($loglevel != null)
+ {
+ self::$loglevel = $loglevel;
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Constructor.
+ */
+ private function __construct($loglevel = 'info')
+ {
+ $this->loglevel = $loglevel;
+ }
+
+ /**
+ * Log dispatcher.
+ *
+ * @param string $message Log message
+ * @param string $level Log level
+ */
+ public function log($message, $level = 'info')
+ {
+ // Available log levels ordered by verbosity.
+ $levels = array_flip(array('fatal', 'info', 'warn', 'error', 'debug'));
+
+ // 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
+ {
+ $this->caller->logSection('isisImporter', "[$level] $message");
+ }
+ }
+
+ /**
+ * Progress notifier.
+ *
+ * @param int $n Row number
+ */
+ public function progress($n)
+ {
+ $this->processed = $n;
+
+ if ($this->section == 'action')
+ {
+ $this->caller->output .= "Saved item $n\n";
+ }
+ else
+ {
+ // Progress bar is just shown if loglevel is 'fatal'.
+ if ($this->loglevel == 'fatal')
+ {
+ $this->caller->progressBar($n, $this->entries);
+ }
+ }
+
+ return $this->processed;
+ }
+}