source: t29-www/lib/logging.php @ 288

Last change on this file since 288 was 275, checked in by sven, 12 years ago

Geraete-Seiten von altem SSI ins neue PHP konvertiert und Einbindung in navigation.xml gestaltet.

  • alle /de-v6/geraete/* sowie /de-v6/details: SSI durch PHP ersetzt, UTF-8-Zeichencode, zum Teil kleinere Korrekturen im HTML-Code. Evventuelle Verschiebungen von CSS und JavaScript nach extern.
  • /de-v6/navigation.xml: Extraseiten einsortiert
  • Alle moeglichen Seiten unter /de-v6/: Links zu Extraseiten korrigiert (.php statt .shtm-Dateiendung)

Verbesserungen am System:

  • cache.php: Debugging-Verbesserungen
  • logging.php: Neu, um besser Loggen zu können. Logging-Ausgaben sollten abgefangen werden und oben auf eine Seite gepackt werden. Ist noch nicht designt und funktioniert auch nicht 100%ig.
  • menu.php: Tests eingearbeitet, damit die Seitenanzeige nicht fehlschlägt wenn das navigation.xml-File kaputt ist.
  • technikum29.php: title und titel-Variablen sollten gleichen Wert haben
  • template.php: Logging-object eingebaut

Ressourcen (CSS/JavaScript)-Veränderungen:

  • 12-sidebar.css: Darstellung fuer .geraete-Links. Sollen spaeter nicht mehr dargestellt werden
  • pagestyles: Einzelne Styles für Extraseiten korrigiert, ebenso Seitenscripts
  • smoothscroll.js: Unabhängig von den Extraseiten: Scrolling zu Ankern basismäßig implementiert.
File size: 2.5 KB
Line 
1<?php
2
3/**
4        Inspired by Klooger,
5        https://github.com/katzgrau/KLogger/
6*/
7class t29Log {
8        const EMERG  = 'emerg';  // Emergency: system is unusable
9        const ALERT  = 'alert';  // Alert: action must be taken immediately
10        const CRIT   = 'crit';   // Critical: critical conditions
11        const ERR    = 'err';    // Error: error conditions
12        const WARN   = 'warn';   // Warning: warning conditions
13        const NOTICE = 'notice'; // Notice: normal but significant condition
14        const INFO   = 'info';   // Informational: informational messages
15        const DEBUG  = 'debug';  // Debug: debug messages
16       
17    /**
18     * We need a default argument value in order to add the ability to easily
19     * print out objects etc. But we can't use NULL, 0, FALSE, etc, because those
20     * are often the values the developers will test for. So we'll make one up.
21     */
22    const NO_ARGUMENTS = 't29Log::NO_ARGUMENTS';
23        /*
24                log array format:
25                        [
26                                [LEVEL,string],
27                                [LEVEL,string],
28                                [LEVEL,string],
29                                ...
30                        ]
31        */
32        public $entries = array();
33       
34        function __construct() {
35                // we shall be the PHP error handler
36                set_error_handler(array($this, 'log_phperror'));
37               
38                // and register a final shutdown function
39                register_shutdown_function(array($this, 'php_shutdown'));
40        }
41       
42        function log($line, $severity, $args = self::NO_ARGUMENTS) {
43                if($args !== self::NO_ARGUMENTS)
44                        $line .= '; '. var_export($args, true);
45                $this->entries[] = array($severity, $line);
46        }
47       
48        function log_phperror($errno, $errstr, $errfile, $errline) {
49                switch($errno) {
50                        case E_WARNING: $errno = self::WARN; break;
51                        case E_NOTICE: $errno = self::NOTICE; break;
52                        default: $errno = self::WARN; break;
53                }
54               
55                $this->log("Error on line <tt class='line'>$errline</tt> in file <tt class='file'>$errfile</tt>:\n<pre>".htmlspecialchars($errstr)."</pre>",
56                        $errno);
57
58                /* Don't execute PHP internal error handler */
59                return true;
60        }
61       
62        function php_shutdown() {
63                if(!$this->is_empty()) {
64                        // we still have errors. print them!
65                        $this->print_all('final shutdown');
66                }
67        }
68       
69        function is_empty() {
70                return empty($this->entries);
71        }
72       
73        function print_all($ul_classes='') {
74                // causal printing function. Flushes entries afterwards!
75                print "<ul class='$ul_classes'>";
76                foreach($this->entries as $entry) {
77                        printf('<li class="%s">%s</li>'.PHP_EOL, $entry[0], $entry[1]);
78                }
79                print "</ul>";
80                $this->entries = array(); // flush entries!
81        }
82       
83        // convenience functions
84        public function FATAL($line, $args = self::NO_ARGUMENTS){
85                $this->log($line, self::FATAL, $args);
86        }
87
88       
89       
90} // class
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License