diff --git a/library/log4php/appenders/LoggerAppenderConsole.php b/library/log4php/appenders/LoggerAppenderConsole.php new file mode 100644 --- /dev/null +++ b/library/log4php/appenders/LoggerAppenderConsole.php @@ -0,0 +1,103 @@ +fp = fopen($this->target, 'w'); + if (is_resource($this->fp) && $this->layout !== null) { + fwrite($this->fp, $this->layout->getHeader()); + } + $this->closed = (bool)is_resource($this->fp) === false; + } + + + public function close() { + if ($this->closed != true) { + if (is_resource($this->fp) && $this->layout !== null) { + fwrite($this->fp, $this->layout->getFooter()); + fclose($this->fp); + } + $this->closed = true; + } + } + + public function append(LoggerLoggingEvent $event) { + if (is_resource($this->fp) && $this->layout !== null) { + fwrite($this->fp, $this->layout->format($event)); + } + } + + /** + * Sets the 'target' parameter. + * @param string $target + */ + public function setTarget($target) { + $value = trim($target); + if ($value == self::STDOUT || strtoupper($value) == 'STDOUT') { + $this->target = self::STDOUT; + } elseif ($value == self::STDERR || strtoupper($value) == 'STDERR') { + $this->target = self::STDERR; + } else { + $target = var_export($target); + $this->warn("Invalid value given for 'target' property: [$target]. Property not set."); + } + } + + /** + * Returns the value of the 'target' parameter. + * @return string + */ + public function getTarget() { + return $this->target; + } +}