Permalink
Browse files

Added stdout logging class

  • Loading branch information...
1 parent 66159a4 commit a502def2fbeb5d92c8497c6f7614d763e55faeeb @mjpearson committed May 26, 2010
Showing with 55 additions and 0 deletions.
  1. +3 −0 lib/ColumnContainer.class.php
  2. +52 −0 lib/logging/LoggerSTDOUT.class.php
View
3 lib/ColumnContainer.class.php
@@ -28,6 +28,9 @@
/* @var int 'STRING' container type (untranslated bytes/ascii/utf8/long types) */
const TYPE_STRING = 2;
+ /* @var int 'LONG' container type @todo - not implemented! */
+ const TYPE_LONG = 3;
+
/* @var array complete list of errors for this object instance */
public $errors = array();
View
52 lib/logging/LoggerSTDOUT.class.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * PandraLoggerSTDOUT
+ *
+ * Sends all logging events to standard output (unbuffered)
+ *
+ * @author Michael Pearson <pandra-support@phpgrease.net>
+ * @copyright 2010 phpgrease.net
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
+ * @version 0.2
+ * @package pandra
+ */
+class PandraLoggerSTDOUT implements PandraLogger {
+
+ private $_isOpen = true;
+
+ private $_htmlMode = FALSE;
+
+ public function __construct(array $params) {
+ if (array_key_exists('htmlMode', $params)) {
+ $this->_htmlMode = (bool) $params['htmlMode'];
+ }
+ return $this->_isOpen;
+ }
+
+ public function isOpen() {
+ return $this->_isOpen;
+ }
+
+ /**
+ * Log everything
+ * @param int $priority requested priority log
+ * @return boolean this logger will log for priority
+ */
+ public function isPriorityLogger($priority) {
+ return TRUE;
+ }
+
+ public function execute($priority, $message) {
+ $out = PandraLog::$priorityMap[$priority] . ": " . $message . "\n";
+
+ if ($this->_htmlMode) $out = nl2br($out);
+
+ if ($priority == PandraLog::LOG_CRIT) {
+ throw new RuntimeException($out);
+ } else {
+ echo $out;
+ return TRUE;
+ }
+ }
+}
+?>

0 comments on commit a502def

Please sign in to comment.