dmBridge PHP API
DMLogger.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00016 class DMLogger {
00017 
00019    private $client_ip;
00021    private $facility;
00023    private $priority;
00025    private $uri;
00026 
00027    public function __construct() {
00028       $this->setClientIP($_SERVER['REMOTE_ADDR']);
00029       $this->setFacility(LOG_USER);
00030       $this->setPriority(LOG_NOTICE);
00031       $this->setURI(DMHTTPRequest::getCurrent()->getURI());
00032    }
00033 
00038    public function log(DMLoggable $obj) {
00039       if (!DMConfigXML::getInstance()->isLoggingEnabled()) {
00040          return;
00041       }
00042 
00043       if (stripos($_SERVER['SERVER_SOFTWARE'], 'microsoft') !== false) {
00044          // windows only supports LOG_USER
00045          openlog("dmBridge", LOG_ODELAY, LOG_USER);
00046       } else {
00047          openlog("dmBridge", LOG_ODELAY, $this->getFacility());
00048       }
00049       syslog($obj->getLogPriority(), $obj->getLogMessage());
00050       closelog();
00051 
00052       $obj->setHasBeenLogged(true);
00053    }
00054 
00058    public function getClientIP() {
00059       return $this->client_ip;
00060    }
00061 
00066    public function setClientIP($ip) {
00067       if (!DMString::isValidIPv4Address($ip)) {
00068          throw new DMIllegalArgumentException(
00069             sprintf(DMLocalizedString::getString("INVALID_IP"), $ip));
00070       }
00071       $this->client_ip = $ip;
00072    }
00073 
00077    public function getFacility() {
00078       return $this->facility;
00079    }
00080 
00084    public function setFacility($facility) {
00085       $this->facility = $facility;
00086    }
00087 
00091    public function getPriority() {
00092       return $this->priority;
00093    }
00094 
00098    public function setPriority($priority) {
00099       $this->priority = $priority;
00100    }
00101 
00105    public function getURI() {
00106       return $this->uri;
00107    }
00108 
00112    public function setURI(DMURI $uri) {
00113       $this->uri = $uri;
00114    }
00115 
00116 }
 All Data Structures Functions Variables