MediaSearch_Log
[ class tree: MediaSearch_Log ] [ index: MediaSearch_Log ] [ all elements ]

Source for file File.php

Documentation is available at File.php

  1. <?php
  2. /**
  3.  * MediaSearch
  4.  *
  5.  * LICENSE
  6.  *
  7.  * "THE BEER-WARE LICENSE" (Revision 42):
  8.  * "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
  9.  * As long as you retain this notice you can do whatever you want with
  10.  * this stuff. If we meet some day, and you think this stuff is worth it,
  11.  * you can buy me a beer in return.
  12.  *
  13.  * $Author$
  14.  * $Revision$
  15.  *
  16.  * @category    MediaSearch
  17.  * @package     MediaSearch_Log
  18.  * @copyright   Copyright (c) 2009 Sven Strittmatter
  19.  */
  20.  
  21. /**
  22.  * @see MediaSearch_Log_Abstract
  23.  */
  24. require_once('MediaSearch/Log/Abstract.php');
  25.  
  26. /**
  27.   * @todo Write apidoc.
  28.   *
  29.   * @category   MediaSearch
  30.   * @package    MediaSearch_Log
  31.   * @copyright  Copyright (c) 2009 Sven Strittmatter
  32.   */
  33.     const TRACE_LELVEL = 48;
  34.  
  35.     private $logFile;
  36.  
  37.     public function __construct($fileName$logLevel Log::DISABLED{
  38.         $this->setFileName($fileName);
  39.         $this->setLevel($logLevel);
  40.     }
  41.  
  42.     public function setFileName($string{
  43.         if (!file_exists($string&& !is_writeable(dirname($string))) {
  44.             $message  "The log file $string does not exist ";
  45.             $message .= 'and the parent directory is not writable!';
  46.             throw new InvalidArgumentException($message);
  47.         else if (file_exists($string&& !is_writable($string)) {
  48.             $message  "The log file $string is not writeable!";
  49.             throw new InvalidArgumentException($message);
  50.         }
  51.  
  52.         $this->logFile $string;
  53.     }
  54.  
  55.     public function getFileName({
  56.         $this->logFile;
  57.     }
  58.  
  59.     protected function getPreamble($level$traceLevel null{
  60.     $string '[';
  61.  
  62.         switch ($level{
  63.             case MediaSearch_Log::INFO:
  64.                 $string .= 'INFO';
  65.                 break;
  66.             case MediaSearch_Log::TRACE:
  67.                 $string .= 'TRACE-' $traceLevel;
  68.                 break;
  69.             case MediaSearch_Log::DEBUG:
  70.                 $string .= 'DEBUG';
  71.                 break;
  72.             case MediaSearch_Log::WARN:
  73.                 $string .= 'WARN';
  74.                 break;
  75.             case MediaSearch_Log::ERROR:
  76.                 $string .= 'ERROR';
  77.                 break;
  78.             case MediaSearch_Log::FATAL:
  79.                 $string .= 'FATAL';
  80.                 break;
  81.             default:
  82.                 return '';
  83.         }
  84.  
  85.         $string .= ']';
  86.     $string str_pad($string15);
  87.  
  88.     return $string;
  89.     }
  90.     
  91.     protected function log($messagearray $variables null{
  92.         if (null !== $variables{
  93.             $message .= ' Variables: ';
  94.  
  95.             foreach ($variables as $variable{
  96.                 $message .= print_r($variabletrue);
  97.             }
  98.         }
  99.  
  100.         $message .= "\n";
  101.         $succeded file_put_contents($this->logFile$messageFILE_APPEND);
  102.  
  103.         if (false === $succeded{
  104.             $message  'Cant put content to file: ' $this->$logFile;
  105.             throw new RuntimeException($message);
  106.         }
  107.     }
  108. }

Documentation generated on Mon, 17 Aug 2009 14:52:36 +0200 by phpDocumentor 1.4.2