StreamLogger.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: StreamLogger.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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                 // boo.
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 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4