XML-basierter Logger wurde ausgelagert in ein konfigurierbares Array
authorMarkus Bröker <broeker.markus@googlemail.com>
Fri, 13 Nov 2015 17:47:37 +0100
changeset 15 560d53f840fa
parent 14 07805bde6517
child 16 f09eccb386ca
XML-basierter Logger wurde ausgelagert in ein konfigurierbares Array
classes/bfw/Configuration.php
config/config.php
config/log4php.xml
new file mode 100644
--- /dev/null
+++ b/classes/bfw/Configuration.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * Copyright(C) 2015 Markus Bröker<broeker.markus@googlemail.com>
+ *
+ */
+
+namespace bfw;
+
+class Configuration {
+
+    /**
+     * Standard-Autoloader für die Basis-Klassen des Projekts
+     *
+     * @param $class
+     * @return bool
+     */
+    public static function bfw_autoLoader($class) {
+        $nsClass = str_replace('\\', '/', $class);
+        $filename = sprintf('%s/classes/%s.php', BFW_PATH, $nsClass);
+        $classPath = sprintf('classes/%s.php', $nsClass);
+
+        if (file_exists($filename)) {
+            require_once BFW_PATH . "/$classPath";
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * @return array
+     */
+    public static function bfw_loggerConfiguration() {
+        return array(
+            'rootLogger' => array('appenders' => array('default')),
+            'appenders' => array(
+                'default' => array(
+                    'class' => 'LoggerAppenderFile',
+                    'layout' => array('class' => 'LoggerLayoutSimple'),
+                    'params' => array(
+                        'file' => BFW_PATH . '/logs/bfw.log',
+                        'append' => true
+                    )
+                )
+            )
+        );
+    }
+}
\ No newline at end of file
--- a/config/config.php
+++ b/config/config.php
@@ -6,31 +6,12 @@
 
 define('BFW_PATH', dirname(dirname(__FILE__)));
 
-/**
- * Standard-Autoloader für die Basis-Klassen des Projekts
- *
- * @param $class
- * @return bool
- */
-function bfw_autoLoader($class) {
-    $nsClass = str_replace('\\', '/', $class);
-    $filename = sprintf('%s/classes/%s.php', BFW_PATH, $nsClass);
-    $classPath = sprintf('classes/%s.php', $nsClass);
+require_once BFW_PATH . '/classes/bfw/Configuration.php';
+require_once BFW_PATH . '/library/log4php/Logger.php';
 
-    if (file_exists($filename)) {
-        require_once BFW_PATH . "/$classPath";
-
-        return true;
-    }
+Logger::configure(bfw\Configuration::bfw_loggerConfiguration());
+spl_autoload_register('bfw\Configuration::bfw_autoLoader');
 
-    return false;
-}
-
-require_once BFW_PATH . '/library/log4php/Logger.php';
-Logger::configure(BFW_PATH . '/config/log4php.xml');
-
-spl_autoload_register('bfw_autoLoader');
-
-// Durchs Überschreiben habe ich eine eigene Session und teile mir diese nicht mit den 'PHPSESSID' Leuten...
+// Session Handling
 session_name('bfw-id');
 session_start();
\ No newline at end of file
deleted file mode 100644
--- a/config/log4php.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration xmlns="http://logging.apache.org/log4php/">
-    <appender name="default" class="LoggerAppenderFile">
-        <layout class="LoggerLayoutSimple"/>
-        <param name="file" value="/var/www/vhosts/BFW_APP/logs/bfw.log"/>
-        <param name="append" value="true"/>
-    </appender>
-    <root>
-        <appender_ref ref="default"/>
-    </root>
-</configuration>