Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

  • Log_Writer_Abstract
  • Log_Writer_Bd
  • Log_Writer_File
  • Log_Writer_Syslog
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Pry Framework
  4:  *
  5:  * LICENSE
  6:  *
  7:  * This source file is subject to the new BSD license that is bundled
  8:  * with this package in the file LICENSE.txt.
  9:  * 
 10:  * @version $Revision: 154 $
 11:  */
 12: 
 13: /**
 14:  * Class d'écriture de log sur un serveur Syslog
 15:  *
 16:  * @package Log
 17:  * @subpackage Log_Writer
 18:  * @version 1.0.0
 19:  * @author Olivier ROGER <oroger.fr>
 20:  *
 21:  */
 22: class Log_Writer_Syslog extends Log_Writer_Abstract
 23: {
 24:     const FACILITY_KERNEL           = 0;
 25:     const FACILITY_USER_LEVEL       = 1;
 26:     const FACILITY_MAIL_SYSTEM      = 2;
 27:     const FACILITY_SYSTEM_DEAMON    = 3;
 28:     const FACILITY_SECURITY_MSG     = 4;
 29:     const FACILITY_INTERNAL_SYSLOG  = 5;
 30:     const FACILITY_LINE_PRINTER     = 6;
 31:     const FACILITY_NETWK_NEWS       = 7;
 32:     const FACILITY_UUCP             = 8;
 33:     const FACILITY_CLOCK_DEAMON     = 9;
 34:     const FACILITY_AUTH_MSG         = 10;
 35:     const FACILITY_FTP_DEAMON       = 11;
 36:     const FACILITY_NTP              = 12;
 37:     const FACILITY_LOG_AUDIT        = 13;
 38:     const FACILITY_LOG_ALERT        = 14;
 39:     const FACILITY_LOCAL_USE0       = 16;
 40:     const FACILITY_LOCAL_USE1       = 17;
 41:     const FACILITY_LOCAL_USE2       = 18;
 42:     const FACILITY_LOCAL_USE3       = 19;
 43:     const FACILITY_LOCAL_USE4       = 20;
 44:     const FACILITY_LOCAL_USE5       = 21;
 45:     const FACILITY_LOCAL_USE6       = 22;
 46:     const FACILITY_LOCAL_USE7       = 23;
 47: 
 48:     /**
 49:      * Serveur syslog
 50:      * @var string
 51:      */
 52:     private $syslogServer;
 53: 
 54:     /**
 55:      * Port de communication
 56:      * @var int
 57:      */
 58:     private $port;
 59: 
 60:     /**
 61:      * Facility
 62:      * @var int
 63:      */
 64:     private $facility   = 1;
 65: 
 66:     /**
 67:      * Niveau de sévérité
 68:      * @var int
 69:      */
 70:     private $severity   = null;
 71: 
 72:     /**
 73:      * Application émettant le message
 74:      * @var string
 75:      */
 76:     private $app        = '';
 77: 
 78:     /**
 79:      * Constructeur
 80:      * @param string $host IP du serveur
 81:      * @param string $port Port de communication. defaut 514
 82:      */
 83:     public function __construct($host,$port = 514)
 84:     {
 85:         $this->syslogServer = 'udp://'.$host;
 86:         $this->port = intval($port);
 87:     }
 88: 
 89:     /**
 90:      * Défini le niveau de "Facility" 0- 23
 91:      * @see http://fr.wikipedia.org/wiki/Syslog
 92:      * @param int $facility
 93:      */
 94:     public function setFacility($facility)
 95:     {
 96:         $facility = intval($facility);
 97:         if($facility < 24)
 98:             $this->facility = $facility;
 99:         else
100:             throw new RangeException('Facility doit être compris entre 0 et 23');
101:     }
102: 
103:     /**
104:      * Défini la sévérité du message
105:      * @param int $severity
106:      */
107:     public function setSeverity($severity)
108:     {
109:         $severity = intval($severity);
110:         if($severity < 8)
111:             $this->severity = $severity;
112:         else
113:             throw new RangeException ('Severity doit être compris entre 0 et 7');
114:     }
115: 
116:     /**
117:      * Défini l'application envoyant le message
118:      * @param string $app
119:      */
120:     public function setApp($app)
121:     {
122:         $this->app = $app;
123:     }
124: 
125:     /**
126:      * Ecriture du message vers le serveur syslog
127:      * @param string $message
128:      * @param int $level Niveau d'importance
129:      */
130:     protected function _write($message,$level)
131:     {
132:         $content        = $this->app.':'.$message;
133:         if(empty($this->severity))
134:             $this->severity = $level;
135:         
136:         $pri            = '<'.($this->facility*8+$this->severity).'>';
137:         $header         = $_SERVER['REMOTE_ADDR'].' ';
138:         $syslogMsg      = $pri.$header.$content;
139:         $socket         = fsockopen($this->syslogServer,$this->port);
140: 
141:         if($socket)
142:         {
143:             fwrite($socket,$syslogMsg);
144:             fclose($socket);
145:         }
146:         else
147:         {
148:             throw new Exception('Impossible de contacter le serveur Syslog');
149:         }
150:     }
151: }
152: ?>
153: 
Pry Framework API documentation generated by ApiGen 2.6.1