Пример #1
0
 /**
  * Gets the singleton logger instance.
  *
  * @param $name String Name of the target log file.
  * @return Logger The logger instance.
  * @static
  */
 public static function getLogger($name = "")
 {
     if ($name == "") {
         $name = "main";
     }
     if (frontend::$logger == null) {
         // set up logger array
         frontend::$logger = array();
     }
     if (!isset(frontend::$logger[$name])) {
         $admin = false;
         $filename = "";
         // create new instance and add to array
         if (file_exists(BASEDIR . "core/log4php/Logger.php")) {
             $filename = BASEDIR . "core/log4php/Logger.php";
             include_once $filename;
         } else {
             if (file_exists(BASEDIR . "../core/log4php/Logger.php")) {
                 $filename = BASEDIR . "../core/log4php/Logger.php";
                 include_once $filename;
                 $admin = true;
             } else {
                 throw new Exception("Logger could not be loaded. File not found");
             }
         }
         // check if config file has to be created, either because it does not exist
         // or the template file is newer than the existing one.
         $templatefile = BASEDIR . ($admin ? "../" : "") . "files/static/log4php/config-template.xml";
         $logfile = $admin == true ? BASEDIR . "../files/static/log4php/adminconfig.xml" : BASEDIR . "files/static/log4php/config.xml";
         if (!file_exists($logfile) || filectime($logfile) < filectime($templatefile) || strpos(file_get_contents($logfile), $templatefile) !== true) {
             $xml = file_get_contents($templatefile);
             $xml = str_replace('{{path}}', BASEDIR, $xml);
             file_put_contents($logfile, $xml);
         }
         Logger::configure($logfile);
         frontend::$logger[$name] = Logger::getLogger($name == "" ? "log" : $name);
     }
     return frontend::$logger[$name];
 }