00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class StreamLogger extends BaseLogger
00017 {
00018 private $stream = null;
00019
00020 public function __destruct()
00021 {
00022 try {
00023 $this->close();
00024 } catch (BaseException $e) {
00025
00026 }
00027 }
00028
00032 public static function create()
00033 {
00034 return new self;
00035 }
00036
00040 public function getOutputStream()
00041 {
00042 return $this->stream;
00043 }
00044
00048 public function setOutputStream(OutputStream $stream)
00049 {
00050 $this->stream = $stream;
00051
00052 return $this;
00053 }
00054
00058 public function flush()
00059 {
00060 if ($this->stream)
00061 $this->stream->flush();
00062
00063 return $this;
00064 }
00065
00069 public function close()
00070 {
00071 if ($this->stream) {
00072
00073 $this->flush();
00074 $this->stream->close();
00075
00076 $this->stream = null;
00077 }
00078
00079 return $this;
00080 }
00081
00085 protected function publish(LogRecord $record)
00086 {
00087 if (!$this->stream)
00088 return $this;
00089
00090 $this->stream->write($record->toString()."\n");
00091
00092 return $this;
00093 }
00094 }
00095 ?>